.. | .. |
---|
89 | 89 | /* For higher baud Rates use TIOCEXBAUD */ |
---|
90 | 90 | #define TIOCEXBAUD 0x5462 |
---|
91 | 91 | |
---|
92 | | -/* vendor id and device id defines */ |
---|
93 | | - |
---|
94 | | -/* The native mos7840/7820 component */ |
---|
95 | | -#define USB_VENDOR_ID_MOSCHIP 0x9710 |
---|
96 | | -#define MOSCHIP_DEVICE_ID_7840 0x7840 |
---|
97 | | -#define MOSCHIP_DEVICE_ID_7820 0x7820 |
---|
98 | | -#define MOSCHIP_DEVICE_ID_7810 0x7810 |
---|
99 | | -/* The native component can have its vendor/device id's overridden |
---|
100 | | - * in vendor-specific implementations. Such devices can be handled |
---|
101 | | - * by making a change here, in id_table. |
---|
| 92 | +/* |
---|
| 93 | + * Vendor id and device id defines |
---|
| 94 | + * |
---|
| 95 | + * NOTE: Do not add new defines, add entries directly to the id_table instead. |
---|
102 | 96 | */ |
---|
103 | 97 | #define USB_VENDOR_ID_BANDB 0x0856 |
---|
104 | 98 | #define BANDB_DEVICE_ID_USO9ML2_2 0xAC22 |
---|
.. | .. |
---|
113 | 107 | #define BANDB_DEVICE_ID_USOPTL4_2P 0xBC02 |
---|
114 | 108 | #define BANDB_DEVICE_ID_USOPTL4_4 0xAC44 |
---|
115 | 109 | #define BANDB_DEVICE_ID_USOPTL4_4P 0xBC03 |
---|
116 | | - |
---|
117 | | -/* This driver also supports |
---|
118 | | - * ATEN UC2324 device using Moschip MCS7840 |
---|
119 | | - * ATEN UC2322 device using Moschip MCS7820 |
---|
120 | | - * MOXA UPort 2210 device using Moschip MCS7820 |
---|
121 | | - */ |
---|
122 | | -#define USB_VENDOR_ID_ATENINTL 0x0557 |
---|
123 | | -#define ATENINTL_DEVICE_ID_UC2324 0x2011 |
---|
124 | | -#define ATENINTL_DEVICE_ID_UC2322 0x7820 |
---|
125 | | - |
---|
126 | | -#define USB_VENDOR_ID_MOXA 0x110a |
---|
127 | | -#define MOXA_DEVICE_ID_2210 0x2210 |
---|
128 | 110 | |
---|
129 | 111 | /* Interrupt Routine Defines */ |
---|
130 | 112 | |
---|
.. | .. |
---|
173 | 155 | #define LED_OFF_MS 500 |
---|
174 | 156 | |
---|
175 | 157 | enum mos7840_flag { |
---|
176 | | - MOS7840_FLAG_CTRL_BUSY, |
---|
177 | 158 | MOS7840_FLAG_LED_BUSY, |
---|
178 | 159 | }; |
---|
179 | 160 | |
---|
| 161 | +#define MCS_PORT_MASK GENMASK(2, 0) |
---|
| 162 | +#define MCS_PORTS(nr) ((nr) & MCS_PORT_MASK) |
---|
| 163 | +#define MCS_LED BIT(3) |
---|
| 164 | + |
---|
| 165 | +#define MCS_DEVICE(vid, pid, flags) \ |
---|
| 166 | + USB_DEVICE((vid), (pid)), .driver_info = (flags) |
---|
| 167 | + |
---|
180 | 168 | static const struct usb_device_id id_table[] = { |
---|
181 | | - {USB_DEVICE(USB_VENDOR_ID_MOSCHIP, MOSCHIP_DEVICE_ID_7840)}, |
---|
182 | | - {USB_DEVICE(USB_VENDOR_ID_MOSCHIP, MOSCHIP_DEVICE_ID_7820)}, |
---|
183 | | - {USB_DEVICE(USB_VENDOR_ID_MOSCHIP, MOSCHIP_DEVICE_ID_7810)}, |
---|
184 | | - {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USO9ML2_2)}, |
---|
185 | | - {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USO9ML2_2P)}, |
---|
186 | | - {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USO9ML2_4)}, |
---|
187 | | - {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USO9ML2_4P)}, |
---|
188 | | - {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_US9ML2_2)}, |
---|
189 | | - {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_US9ML2_4)}, |
---|
190 | | - {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USPTL4_2)}, |
---|
191 | | - {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USPTL4_4)}, |
---|
192 | | - {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL4_2)}, |
---|
193 | | - {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL4_2P)}, |
---|
194 | | - {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL4_4)}, |
---|
195 | | - {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL4_4P)}, |
---|
196 | | - {USB_DEVICE(USB_VENDOR_ID_ATENINTL, ATENINTL_DEVICE_ID_UC2324)}, |
---|
197 | | - {USB_DEVICE(USB_VENDOR_ID_ATENINTL, ATENINTL_DEVICE_ID_UC2322)}, |
---|
198 | | - {USB_DEVICE(USB_VENDOR_ID_MOXA, MOXA_DEVICE_ID_2210)}, |
---|
| 169 | + { MCS_DEVICE(0x0557, 0x2011, MCS_PORTS(4)) }, /* ATEN UC2324 */ |
---|
| 170 | + { MCS_DEVICE(0x0557, 0x7820, MCS_PORTS(2)) }, /* ATEN UC2322 */ |
---|
| 171 | + { MCS_DEVICE(0x110a, 0x2210, MCS_PORTS(2)) }, /* Moxa UPort 2210 */ |
---|
| 172 | + { MCS_DEVICE(0x9710, 0x7810, MCS_PORTS(1) | MCS_LED) }, /* ASIX MCS7810 */ |
---|
| 173 | + { MCS_DEVICE(0x9710, 0x7820, MCS_PORTS(2)) }, /* MosChip MCS7820 */ |
---|
| 174 | + { MCS_DEVICE(0x9710, 0x7840, MCS_PORTS(4)) }, /* MosChip MCS7840 */ |
---|
| 175 | + { MCS_DEVICE(0x9710, 0x7843, MCS_PORTS(3)) }, /* ASIX MCS7840 3 port */ |
---|
| 176 | + { USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USO9ML2_2) }, |
---|
| 177 | + { USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USO9ML2_2P) }, |
---|
| 178 | + { USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USO9ML2_4) }, |
---|
| 179 | + { USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USO9ML2_4P) }, |
---|
| 180 | + { USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_US9ML2_2) }, |
---|
| 181 | + { USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_US9ML2_4) }, |
---|
| 182 | + { USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USPTL4_2) }, |
---|
| 183 | + { USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USPTL4_4) }, |
---|
| 184 | + { USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL4_2) }, |
---|
| 185 | + { USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL4_2P) }, |
---|
| 186 | + { USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL4_4) }, |
---|
| 187 | + { USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL4_4P) }, |
---|
199 | 188 | {} /* terminating entry */ |
---|
200 | 189 | }; |
---|
201 | 190 | MODULE_DEVICE_TABLE(usb, id_table); |
---|
.. | .. |
---|
207 | 196 | struct urb *read_urb; /* read URB for this port */ |
---|
208 | 197 | __u8 shadowLCR; /* last LCR value received */ |
---|
209 | 198 | __u8 shadowMCR; /* last MCR value received */ |
---|
210 | | - char open; |
---|
211 | | - char open_ports; |
---|
212 | 199 | struct usb_serial_port *port; /* loop back to the owner of this object */ |
---|
213 | 200 | |
---|
214 | 201 | /* Offsets */ |
---|
215 | 202 | __u8 SpRegOffset; |
---|
216 | 203 | __u8 ControlRegOffset; |
---|
217 | 204 | __u8 DcrRegOffset; |
---|
218 | | - /* for processing control URBS in interrupt context */ |
---|
219 | | - struct urb *control_urb; |
---|
220 | | - struct usb_ctrlrequest *dr; |
---|
221 | | - char *ctrl_buf; |
---|
222 | | - int MsrLsr; |
---|
223 | 205 | |
---|
224 | 206 | spinlock_t pool_lock; |
---|
225 | 207 | struct urb *write_urb_pool[NUM_URBS]; |
---|
.. | .. |
---|
301 | 283 | val = val & 0x00ff; |
---|
302 | 284 | /* For the UART control registers, the application number need |
---|
303 | 285 | to be Or'ed */ |
---|
304 | | - if (port->serial->num_ports == 4) { |
---|
| 286 | + if (port->serial->num_ports == 2 && port->port_number != 0) |
---|
| 287 | + val |= ((__u16)port->port_number + 2) << 8; |
---|
| 288 | + else |
---|
305 | 289 | val |= ((__u16)port->port_number + 1) << 8; |
---|
306 | | - } else { |
---|
307 | | - if (port->port_number == 0) { |
---|
308 | | - val |= ((__u16)port->port_number + 1) << 8; |
---|
309 | | - } else { |
---|
310 | | - val |= ((__u16)port->port_number + 2) << 8; |
---|
311 | | - } |
---|
312 | | - } |
---|
313 | 290 | dev_dbg(&port->dev, "%s application number is %x\n", __func__, val); |
---|
314 | 291 | return usb_control_msg(dev, usb_sndctrlpipe(dev, 0), MCS_WRREQ, |
---|
315 | 292 | MCS_WR_RTYPE, val, reg, NULL, 0, |
---|
.. | .. |
---|
335 | 312 | return -ENOMEM; |
---|
336 | 313 | |
---|
337 | 314 | /* Wval is same as application number */ |
---|
338 | | - if (port->serial->num_ports == 4) { |
---|
| 315 | + if (port->serial->num_ports == 2 && port->port_number != 0) |
---|
| 316 | + Wval = ((__u16)port->port_number + 2) << 8; |
---|
| 317 | + else |
---|
339 | 318 | Wval = ((__u16)port->port_number + 1) << 8; |
---|
340 | | - } else { |
---|
341 | | - if (port->port_number == 0) { |
---|
342 | | - Wval = ((__u16)port->port_number + 1) << 8; |
---|
343 | | - } else { |
---|
344 | | - Wval = ((__u16)port->port_number + 2) << 8; |
---|
345 | | - } |
---|
346 | | - } |
---|
347 | 319 | dev_dbg(&port->dev, "%s application number is %x\n", __func__, Wval); |
---|
348 | 320 | ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), MCS_RDREQ, |
---|
349 | 321 | MCS_RD_RTYPE, Wval, reg, buf, VENDOR_READ_LENGTH, |
---|
.. | .. |
---|
371 | 343 | |
---|
372 | 344 | /************************************************************************/ |
---|
373 | 345 | /************************************************************************/ |
---|
374 | | -/* I N T E R F A C E F U N C T I O N S */ |
---|
375 | | -/* I N T E R F A C E F U N C T I O N S */ |
---|
376 | | -/************************************************************************/ |
---|
377 | | -/************************************************************************/ |
---|
378 | | - |
---|
379 | | -static inline void mos7840_set_port_private(struct usb_serial_port *port, |
---|
380 | | - struct moschip_port *data) |
---|
381 | | -{ |
---|
382 | | - usb_set_serial_port_data(port, (void *)data); |
---|
383 | | -} |
---|
384 | | - |
---|
385 | | -static inline struct moschip_port *mos7840_get_port_private(struct |
---|
386 | | - usb_serial_port |
---|
387 | | - *port) |
---|
388 | | -{ |
---|
389 | | - return (struct moschip_port *)usb_get_serial_port_data(port); |
---|
390 | | -} |
---|
391 | | - |
---|
392 | | -static void mos7840_handle_new_msr(struct moschip_port *port, __u8 new_msr) |
---|
393 | | -{ |
---|
394 | | - struct moschip_port *mos7840_port; |
---|
395 | | - struct async_icount *icount; |
---|
396 | | - mos7840_port = port; |
---|
397 | | - if (new_msr & |
---|
398 | | - (MOS_MSR_DELTA_CTS | MOS_MSR_DELTA_DSR | MOS_MSR_DELTA_RI | |
---|
399 | | - MOS_MSR_DELTA_CD)) { |
---|
400 | | - icount = &mos7840_port->port->icount; |
---|
401 | | - |
---|
402 | | - /* update input line counters */ |
---|
403 | | - if (new_msr & MOS_MSR_DELTA_CTS) |
---|
404 | | - icount->cts++; |
---|
405 | | - if (new_msr & MOS_MSR_DELTA_DSR) |
---|
406 | | - icount->dsr++; |
---|
407 | | - if (new_msr & MOS_MSR_DELTA_CD) |
---|
408 | | - icount->dcd++; |
---|
409 | | - if (new_msr & MOS_MSR_DELTA_RI) |
---|
410 | | - icount->rng++; |
---|
411 | | - |
---|
412 | | - wake_up_interruptible(&port->port->port.delta_msr_wait); |
---|
413 | | - } |
---|
414 | | -} |
---|
415 | | - |
---|
416 | | -static void mos7840_handle_new_lsr(struct moschip_port *port, __u8 new_lsr) |
---|
417 | | -{ |
---|
418 | | - struct async_icount *icount; |
---|
419 | | - |
---|
420 | | - if (new_lsr & SERIAL_LSR_BI) { |
---|
421 | | - /* |
---|
422 | | - * Parity and Framing errors only count if they |
---|
423 | | - * occur exclusive of a break being |
---|
424 | | - * received. |
---|
425 | | - */ |
---|
426 | | - new_lsr &= (__u8) (SERIAL_LSR_OE | SERIAL_LSR_BI); |
---|
427 | | - } |
---|
428 | | - |
---|
429 | | - /* update input line counters */ |
---|
430 | | - icount = &port->port->icount; |
---|
431 | | - if (new_lsr & SERIAL_LSR_BI) |
---|
432 | | - icount->brk++; |
---|
433 | | - if (new_lsr & SERIAL_LSR_OE) |
---|
434 | | - icount->overrun++; |
---|
435 | | - if (new_lsr & SERIAL_LSR_PE) |
---|
436 | | - icount->parity++; |
---|
437 | | - if (new_lsr & SERIAL_LSR_FE) |
---|
438 | | - icount->frame++; |
---|
439 | | -} |
---|
440 | | - |
---|
441 | | -/************************************************************************/ |
---|
442 | | -/************************************************************************/ |
---|
443 | 346 | /* U S B C A L L B A C K F U N C T I O N S */ |
---|
444 | 347 | /* U S B C A L L B A C K F U N C T I O N S */ |
---|
445 | 348 | /************************************************************************/ |
---|
446 | 349 | /************************************************************************/ |
---|
447 | | - |
---|
448 | | -static void mos7840_control_callback(struct urb *urb) |
---|
449 | | -{ |
---|
450 | | - unsigned char *data; |
---|
451 | | - struct moschip_port *mos7840_port; |
---|
452 | | - struct device *dev = &urb->dev->dev; |
---|
453 | | - __u8 regval = 0x0; |
---|
454 | | - int status = urb->status; |
---|
455 | | - |
---|
456 | | - mos7840_port = urb->context; |
---|
457 | | - |
---|
458 | | - switch (status) { |
---|
459 | | - case 0: |
---|
460 | | - /* success */ |
---|
461 | | - break; |
---|
462 | | - case -ECONNRESET: |
---|
463 | | - case -ENOENT: |
---|
464 | | - case -ESHUTDOWN: |
---|
465 | | - /* this urb is terminated, clean up */ |
---|
466 | | - dev_dbg(dev, "%s - urb shutting down with status: %d\n", __func__, status); |
---|
467 | | - goto out; |
---|
468 | | - default: |
---|
469 | | - dev_dbg(dev, "%s - nonzero urb status received: %d\n", __func__, status); |
---|
470 | | - goto out; |
---|
471 | | - } |
---|
472 | | - |
---|
473 | | - dev_dbg(dev, "%s urb buffer size is %d\n", __func__, urb->actual_length); |
---|
474 | | - if (urb->actual_length < 1) |
---|
475 | | - goto out; |
---|
476 | | - |
---|
477 | | - dev_dbg(dev, "%s mos7840_port->MsrLsr is %d port %d\n", __func__, |
---|
478 | | - mos7840_port->MsrLsr, mos7840_port->port_num); |
---|
479 | | - data = urb->transfer_buffer; |
---|
480 | | - regval = (__u8) data[0]; |
---|
481 | | - dev_dbg(dev, "%s data is %x\n", __func__, regval); |
---|
482 | | - if (mos7840_port->MsrLsr == 0) |
---|
483 | | - mos7840_handle_new_msr(mos7840_port, regval); |
---|
484 | | - else if (mos7840_port->MsrLsr == 1) |
---|
485 | | - mos7840_handle_new_lsr(mos7840_port, regval); |
---|
486 | | -out: |
---|
487 | | - clear_bit_unlock(MOS7840_FLAG_CTRL_BUSY, &mos7840_port->flags); |
---|
488 | | -} |
---|
489 | | - |
---|
490 | | -static int mos7840_get_reg(struct moschip_port *mcs, __u16 Wval, __u16 reg, |
---|
491 | | - __u16 *val) |
---|
492 | | -{ |
---|
493 | | - struct usb_device *dev = mcs->port->serial->dev; |
---|
494 | | - struct usb_ctrlrequest *dr = mcs->dr; |
---|
495 | | - unsigned char *buffer = mcs->ctrl_buf; |
---|
496 | | - int ret; |
---|
497 | | - |
---|
498 | | - if (test_and_set_bit_lock(MOS7840_FLAG_CTRL_BUSY, &mcs->flags)) |
---|
499 | | - return -EBUSY; |
---|
500 | | - |
---|
501 | | - dr->bRequestType = MCS_RD_RTYPE; |
---|
502 | | - dr->bRequest = MCS_RDREQ; |
---|
503 | | - dr->wValue = cpu_to_le16(Wval); /* 0 */ |
---|
504 | | - dr->wIndex = cpu_to_le16(reg); |
---|
505 | | - dr->wLength = cpu_to_le16(2); |
---|
506 | | - |
---|
507 | | - usb_fill_control_urb(mcs->control_urb, dev, usb_rcvctrlpipe(dev, 0), |
---|
508 | | - (unsigned char *)dr, buffer, 2, |
---|
509 | | - mos7840_control_callback, mcs); |
---|
510 | | - mcs->control_urb->transfer_buffer_length = 2; |
---|
511 | | - ret = usb_submit_urb(mcs->control_urb, GFP_ATOMIC); |
---|
512 | | - if (ret) |
---|
513 | | - clear_bit_unlock(MOS7840_FLAG_CTRL_BUSY, &mcs->flags); |
---|
514 | | - |
---|
515 | | - return ret; |
---|
516 | | -} |
---|
517 | 350 | |
---|
518 | 351 | static void mos7840_set_led_callback(struct urb *urb) |
---|
519 | 352 | { |
---|
.. | .. |
---|
591 | 424 | } |
---|
592 | 425 | |
---|
593 | 426 | /***************************************************************************** |
---|
594 | | - * mos7840_interrupt_callback |
---|
595 | | - * this is the callback function for when we have received data on the |
---|
596 | | - * interrupt endpoint. |
---|
597 | | - *****************************************************************************/ |
---|
598 | | - |
---|
599 | | -static void mos7840_interrupt_callback(struct urb *urb) |
---|
600 | | -{ |
---|
601 | | - int result; |
---|
602 | | - int length; |
---|
603 | | - struct moschip_port *mos7840_port; |
---|
604 | | - struct usb_serial *serial; |
---|
605 | | - __u16 Data; |
---|
606 | | - unsigned char *data; |
---|
607 | | - __u8 sp[5], st; |
---|
608 | | - int i, rv = 0; |
---|
609 | | - __u16 wval, wreg = 0; |
---|
610 | | - int status = urb->status; |
---|
611 | | - |
---|
612 | | - switch (status) { |
---|
613 | | - case 0: |
---|
614 | | - /* success */ |
---|
615 | | - break; |
---|
616 | | - case -ECONNRESET: |
---|
617 | | - case -ENOENT: |
---|
618 | | - case -ESHUTDOWN: |
---|
619 | | - /* this urb is terminated, clean up */ |
---|
620 | | - dev_dbg(&urb->dev->dev, "%s - urb shutting down with status: %d\n", |
---|
621 | | - __func__, status); |
---|
622 | | - return; |
---|
623 | | - default: |
---|
624 | | - dev_dbg(&urb->dev->dev, "%s - nonzero urb status received: %d\n", |
---|
625 | | - __func__, status); |
---|
626 | | - goto exit; |
---|
627 | | - } |
---|
628 | | - |
---|
629 | | - length = urb->actual_length; |
---|
630 | | - data = urb->transfer_buffer; |
---|
631 | | - |
---|
632 | | - serial = urb->context; |
---|
633 | | - |
---|
634 | | - /* Moschip get 5 bytes |
---|
635 | | - * Byte 1 IIR Port 1 (port.number is 0) |
---|
636 | | - * Byte 2 IIR Port 2 (port.number is 1) |
---|
637 | | - * Byte 3 IIR Port 3 (port.number is 2) |
---|
638 | | - * Byte 4 IIR Port 4 (port.number is 3) |
---|
639 | | - * Byte 5 FIFO status for both */ |
---|
640 | | - |
---|
641 | | - if (length > 5) { |
---|
642 | | - dev_dbg(&urb->dev->dev, "%s", "Wrong data !!!\n"); |
---|
643 | | - return; |
---|
644 | | - } |
---|
645 | | - |
---|
646 | | - sp[0] = (__u8) data[0]; |
---|
647 | | - sp[1] = (__u8) data[1]; |
---|
648 | | - sp[2] = (__u8) data[2]; |
---|
649 | | - sp[3] = (__u8) data[3]; |
---|
650 | | - st = (__u8) data[4]; |
---|
651 | | - |
---|
652 | | - for (i = 0; i < serial->num_ports; i++) { |
---|
653 | | - mos7840_port = mos7840_get_port_private(serial->port[i]); |
---|
654 | | - wval = ((__u16)serial->port[i]->port_number + 1) << 8; |
---|
655 | | - if (mos7840_port->open) { |
---|
656 | | - if (sp[i] & 0x01) { |
---|
657 | | - dev_dbg(&urb->dev->dev, "SP%d No Interrupt !!!\n", i); |
---|
658 | | - } else { |
---|
659 | | - switch (sp[i] & 0x0f) { |
---|
660 | | - case SERIAL_IIR_RLS: |
---|
661 | | - dev_dbg(&urb->dev->dev, "Serial Port %d: Receiver status error or \n", i); |
---|
662 | | - dev_dbg(&urb->dev->dev, "address bit detected in 9-bit mode\n"); |
---|
663 | | - mos7840_port->MsrLsr = 1; |
---|
664 | | - wreg = LINE_STATUS_REGISTER; |
---|
665 | | - break; |
---|
666 | | - case SERIAL_IIR_MS: |
---|
667 | | - dev_dbg(&urb->dev->dev, "Serial Port %d: Modem status change\n", i); |
---|
668 | | - mos7840_port->MsrLsr = 0; |
---|
669 | | - wreg = MODEM_STATUS_REGISTER; |
---|
670 | | - break; |
---|
671 | | - } |
---|
672 | | - rv = mos7840_get_reg(mos7840_port, wval, wreg, &Data); |
---|
673 | | - } |
---|
674 | | - } |
---|
675 | | - } |
---|
676 | | - if (!(rv < 0)) |
---|
677 | | - /* the completion handler for the control urb will resubmit */ |
---|
678 | | - return; |
---|
679 | | -exit: |
---|
680 | | - result = usb_submit_urb(urb, GFP_ATOMIC); |
---|
681 | | - if (result) { |
---|
682 | | - dev_err(&urb->dev->dev, |
---|
683 | | - "%s - Error %d submitting interrupt urb\n", |
---|
684 | | - __func__, result); |
---|
685 | | - } |
---|
686 | | -} |
---|
687 | | - |
---|
688 | | -static int mos7840_port_paranoia_check(struct usb_serial_port *port, |
---|
689 | | - const char *function) |
---|
690 | | -{ |
---|
691 | | - if (!port) { |
---|
692 | | - pr_debug("%s - port == NULL\n", function); |
---|
693 | | - return -1; |
---|
694 | | - } |
---|
695 | | - if (!port->serial) { |
---|
696 | | - pr_debug("%s - port->serial == NULL\n", function); |
---|
697 | | - return -1; |
---|
698 | | - } |
---|
699 | | - |
---|
700 | | - return 0; |
---|
701 | | -} |
---|
702 | | - |
---|
703 | | -/* Inline functions to check the sanity of a pointer that is passed to us */ |
---|
704 | | -static int mos7840_serial_paranoia_check(struct usb_serial *serial, |
---|
705 | | - const char *function) |
---|
706 | | -{ |
---|
707 | | - if (!serial) { |
---|
708 | | - pr_debug("%s - serial == NULL\n", function); |
---|
709 | | - return -1; |
---|
710 | | - } |
---|
711 | | - if (!serial->type) { |
---|
712 | | - pr_debug("%s - serial->type == NULL!\n", function); |
---|
713 | | - return -1; |
---|
714 | | - } |
---|
715 | | - |
---|
716 | | - return 0; |
---|
717 | | -} |
---|
718 | | - |
---|
719 | | -static struct usb_serial *mos7840_get_usb_serial(struct usb_serial_port *port, |
---|
720 | | - const char *function) |
---|
721 | | -{ |
---|
722 | | - /* if no port was specified, or it fails a paranoia check */ |
---|
723 | | - if (!port || |
---|
724 | | - mos7840_port_paranoia_check(port, function) || |
---|
725 | | - mos7840_serial_paranoia_check(port->serial, function)) { |
---|
726 | | - /* then say that we don't have a valid usb_serial thing, |
---|
727 | | - * which will end up genrating -ENODEV return values */ |
---|
728 | | - return NULL; |
---|
729 | | - } |
---|
730 | | - |
---|
731 | | - return port->serial; |
---|
732 | | -} |
---|
733 | | - |
---|
734 | | -/***************************************************************************** |
---|
735 | 427 | * mos7840_bulk_in_callback |
---|
736 | 428 | * this is the callback function for when we have received data on the |
---|
737 | 429 | * bulk in endpoint. |
---|
.. | .. |
---|
739 | 431 | |
---|
740 | 432 | static void mos7840_bulk_in_callback(struct urb *urb) |
---|
741 | 433 | { |
---|
| 434 | + struct moschip_port *mos7840_port = urb->context; |
---|
| 435 | + struct usb_serial_port *port = mos7840_port->port; |
---|
742 | 436 | int retval; |
---|
743 | 437 | unsigned char *data; |
---|
744 | | - struct usb_serial *serial; |
---|
745 | | - struct usb_serial_port *port; |
---|
746 | | - struct moschip_port *mos7840_port; |
---|
747 | 438 | int status = urb->status; |
---|
748 | | - |
---|
749 | | - mos7840_port = urb->context; |
---|
750 | | - if (!mos7840_port) |
---|
751 | | - return; |
---|
752 | 439 | |
---|
753 | 440 | if (status) { |
---|
754 | 441 | dev_dbg(&urb->dev->dev, "nonzero read bulk status received: %d\n", status); |
---|
755 | | - mos7840_port->read_urb_busy = false; |
---|
756 | | - return; |
---|
757 | | - } |
---|
758 | | - |
---|
759 | | - port = mos7840_port->port; |
---|
760 | | - if (mos7840_port_paranoia_check(port, __func__)) { |
---|
761 | | - mos7840_port->read_urb_busy = false; |
---|
762 | | - return; |
---|
763 | | - } |
---|
764 | | - |
---|
765 | | - serial = mos7840_get_usb_serial(port, __func__); |
---|
766 | | - if (!serial) { |
---|
767 | 442 | mos7840_port->read_urb_busy = false; |
---|
768 | 443 | return; |
---|
769 | 444 | } |
---|
.. | .. |
---|
777 | 452 | tty_flip_buffer_push(tport); |
---|
778 | 453 | port->icount.rx += urb->actual_length; |
---|
779 | 454 | dev_dbg(&port->dev, "icount.rx is %d:\n", port->icount.rx); |
---|
780 | | - } |
---|
781 | | - |
---|
782 | | - if (!mos7840_port->read_urb) { |
---|
783 | | - dev_dbg(&port->dev, "%s", "URB KILLED !!!\n"); |
---|
784 | | - mos7840_port->read_urb_busy = false; |
---|
785 | | - return; |
---|
786 | 455 | } |
---|
787 | 456 | |
---|
788 | 457 | if (mos7840_port->has_led) |
---|
.. | .. |
---|
805 | 474 | |
---|
806 | 475 | static void mos7840_bulk_out_data_callback(struct urb *urb) |
---|
807 | 476 | { |
---|
808 | | - struct moschip_port *mos7840_port; |
---|
809 | | - struct usb_serial_port *port; |
---|
| 477 | + struct moschip_port *mos7840_port = urb->context; |
---|
| 478 | + struct usb_serial_port *port = mos7840_port->port; |
---|
810 | 479 | int status = urb->status; |
---|
811 | 480 | unsigned long flags; |
---|
812 | 481 | int i; |
---|
813 | 482 | |
---|
814 | | - mos7840_port = urb->context; |
---|
815 | | - port = mos7840_port->port; |
---|
816 | 483 | spin_lock_irqsave(&mos7840_port->pool_lock, flags); |
---|
817 | 484 | for (i = 0; i < NUM_URBS; i++) { |
---|
818 | 485 | if (urb == mos7840_port->write_urb_pool[i]) { |
---|
.. | .. |
---|
827 | 494 | return; |
---|
828 | 495 | } |
---|
829 | 496 | |
---|
830 | | - if (mos7840_port_paranoia_check(port, __func__)) |
---|
831 | | - return; |
---|
832 | | - |
---|
833 | | - if (mos7840_port->open) |
---|
834 | | - tty_port_tty_wakeup(&port->port); |
---|
| 497 | + tty_port_tty_wakeup(&port->port); |
---|
835 | 498 | |
---|
836 | 499 | } |
---|
837 | 500 | |
---|
.. | .. |
---|
848 | 511 | |
---|
849 | 512 | static int mos7840_open(struct tty_struct *tty, struct usb_serial_port *port) |
---|
850 | 513 | { |
---|
| 514 | + struct moschip_port *mos7840_port = usb_get_serial_port_data(port); |
---|
| 515 | + struct usb_serial *serial = port->serial; |
---|
851 | 516 | int response; |
---|
852 | 517 | int j; |
---|
853 | | - struct usb_serial *serial; |
---|
854 | 518 | struct urb *urb; |
---|
855 | 519 | __u16 Data; |
---|
856 | 520 | int status; |
---|
857 | | - struct moschip_port *mos7840_port; |
---|
858 | | - struct moschip_port *port0; |
---|
859 | | - |
---|
860 | | - if (mos7840_port_paranoia_check(port, __func__)) |
---|
861 | | - return -ENODEV; |
---|
862 | | - |
---|
863 | | - serial = port->serial; |
---|
864 | | - |
---|
865 | | - if (mos7840_serial_paranoia_check(serial, __func__)) |
---|
866 | | - return -ENODEV; |
---|
867 | | - |
---|
868 | | - mos7840_port = mos7840_get_port_private(port); |
---|
869 | | - port0 = mos7840_get_port_private(serial->port[0]); |
---|
870 | | - |
---|
871 | | - if (mos7840_port == NULL || port0 == NULL) |
---|
872 | | - return -ENODEV; |
---|
873 | 521 | |
---|
874 | 522 | usb_clear_halt(serial->dev, port->write_urb->pipe); |
---|
875 | 523 | usb_clear_halt(serial->dev, port->read_urb->pipe); |
---|
876 | | - port0->open_ports++; |
---|
877 | 524 | |
---|
878 | 525 | /* Initialising the write urb pool */ |
---|
879 | 526 | for (j = 0; j < NUM_URBS; ++j) { |
---|
.. | .. |
---|
1024 | 671 | status = mos7840_set_reg_sync(port, mos7840_port->ControlRegOffset, |
---|
1025 | 672 | Data); |
---|
1026 | 673 | |
---|
1027 | | - /* Check to see if we've set up our endpoint info yet * |
---|
1028 | | - * (can't set it up in mos7840_startup as the structures * |
---|
1029 | | - * were not set up at that time.) */ |
---|
1030 | | - if (port0->open_ports == 1) { |
---|
1031 | | - /* FIXME: Buffer never NULL, so URB is not submitted. */ |
---|
1032 | | - if (serial->port[0]->interrupt_in_buffer == NULL) { |
---|
1033 | | - /* set up interrupt urb */ |
---|
1034 | | - usb_fill_int_urb(serial->port[0]->interrupt_in_urb, |
---|
1035 | | - serial->dev, |
---|
1036 | | - usb_rcvintpipe(serial->dev, |
---|
1037 | | - serial->port[0]->interrupt_in_endpointAddress), |
---|
1038 | | - serial->port[0]->interrupt_in_buffer, |
---|
1039 | | - serial->port[0]->interrupt_in_urb-> |
---|
1040 | | - transfer_buffer_length, |
---|
1041 | | - mos7840_interrupt_callback, |
---|
1042 | | - serial, |
---|
1043 | | - serial->port[0]->interrupt_in_urb->interval); |
---|
1044 | | - |
---|
1045 | | - /* start interrupt read for mos7840 */ |
---|
1046 | | - response = |
---|
1047 | | - usb_submit_urb(serial->port[0]->interrupt_in_urb, |
---|
1048 | | - GFP_KERNEL); |
---|
1049 | | - if (response) { |
---|
1050 | | - dev_err(&port->dev, "%s - Error %d submitting " |
---|
1051 | | - "interrupt urb\n", __func__, response); |
---|
1052 | | - } |
---|
1053 | | - |
---|
1054 | | - } |
---|
1055 | | - |
---|
1056 | | - } |
---|
1057 | | - |
---|
1058 | | - /* see if we've set up our endpoint info yet * |
---|
1059 | | - * (can't set it up in mos7840_startup as the * |
---|
1060 | | - * structures were not set up at that time.) */ |
---|
1061 | | - |
---|
1062 | 674 | dev_dbg(&port->dev, "port number is %d\n", port->port_number); |
---|
1063 | 675 | dev_dbg(&port->dev, "minor number is %d\n", port->minor); |
---|
1064 | 676 | dev_dbg(&port->dev, "Bulkin endpoint is %d\n", port->bulk_in_endpointAddress); |
---|
.. | .. |
---|
1098 | 710 | /* initialize our port settings */ |
---|
1099 | 711 | /* Must set to enable ints! */ |
---|
1100 | 712 | mos7840_port->shadowMCR = MCR_MASTER_IE; |
---|
1101 | | - /* send a open port command */ |
---|
1102 | | - mos7840_port->open = 1; |
---|
1103 | | - /* mos7840_change_port_settings(mos7840_port,old_termios); */ |
---|
1104 | 713 | |
---|
1105 | 714 | return 0; |
---|
1106 | 715 | err: |
---|
.. | .. |
---|
1127 | 736 | static int mos7840_chars_in_buffer(struct tty_struct *tty) |
---|
1128 | 737 | { |
---|
1129 | 738 | struct usb_serial_port *port = tty->driver_data; |
---|
| 739 | + struct moschip_port *mos7840_port = usb_get_serial_port_data(port); |
---|
1130 | 740 | int i; |
---|
1131 | 741 | int chars = 0; |
---|
1132 | 742 | unsigned long flags; |
---|
1133 | | - struct moschip_port *mos7840_port; |
---|
1134 | | - |
---|
1135 | | - if (mos7840_port_paranoia_check(port, __func__)) |
---|
1136 | | - return 0; |
---|
1137 | | - |
---|
1138 | | - mos7840_port = mos7840_get_port_private(port); |
---|
1139 | | - if (mos7840_port == NULL) |
---|
1140 | | - return 0; |
---|
1141 | 743 | |
---|
1142 | 744 | spin_lock_irqsave(&mos7840_port->pool_lock, flags); |
---|
1143 | 745 | for (i = 0; i < NUM_URBS; ++i) { |
---|
.. | .. |
---|
1159 | 761 | |
---|
1160 | 762 | static void mos7840_close(struct usb_serial_port *port) |
---|
1161 | 763 | { |
---|
1162 | | - struct usb_serial *serial; |
---|
1163 | | - struct moschip_port *mos7840_port; |
---|
1164 | | - struct moschip_port *port0; |
---|
| 764 | + struct moschip_port *mos7840_port = usb_get_serial_port_data(port); |
---|
1165 | 765 | int j; |
---|
1166 | 766 | __u16 Data; |
---|
1167 | | - |
---|
1168 | | - if (mos7840_port_paranoia_check(port, __func__)) |
---|
1169 | | - return; |
---|
1170 | | - |
---|
1171 | | - serial = mos7840_get_usb_serial(port, __func__); |
---|
1172 | | - if (!serial) |
---|
1173 | | - return; |
---|
1174 | | - |
---|
1175 | | - mos7840_port = mos7840_get_port_private(port); |
---|
1176 | | - port0 = mos7840_get_port_private(serial->port[0]); |
---|
1177 | | - |
---|
1178 | | - if (mos7840_port == NULL || port0 == NULL) |
---|
1179 | | - return; |
---|
1180 | 767 | |
---|
1181 | 768 | for (j = 0; j < NUM_URBS; ++j) |
---|
1182 | 769 | usb_kill_urb(mos7840_port->write_urb_pool[j]); |
---|
.. | .. |
---|
1192 | 779 | usb_kill_urb(mos7840_port->read_urb); |
---|
1193 | 780 | mos7840_port->read_urb_busy = false; |
---|
1194 | 781 | |
---|
1195 | | - port0->open_ports--; |
---|
1196 | | - dev_dbg(&port->dev, "%s in close%d\n", __func__, port0->open_ports); |
---|
1197 | | - if (port0->open_ports == 0) { |
---|
1198 | | - if (serial->port[0]->interrupt_in_urb) { |
---|
1199 | | - dev_dbg(&port->dev, "Shutdown interrupt_in_urb\n"); |
---|
1200 | | - usb_kill_urb(serial->port[0]->interrupt_in_urb); |
---|
1201 | | - } |
---|
1202 | | - } |
---|
1203 | | - |
---|
1204 | 782 | Data = 0x0; |
---|
1205 | 783 | mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data); |
---|
1206 | 784 | |
---|
1207 | 785 | Data = 0x00; |
---|
1208 | 786 | mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data); |
---|
1209 | | - |
---|
1210 | | - mos7840_port->open = 0; |
---|
1211 | 787 | } |
---|
1212 | 788 | |
---|
1213 | 789 | /***************************************************************************** |
---|
.. | .. |
---|
1217 | 793 | static void mos7840_break(struct tty_struct *tty, int break_state) |
---|
1218 | 794 | { |
---|
1219 | 795 | struct usb_serial_port *port = tty->driver_data; |
---|
| 796 | + struct moschip_port *mos7840_port = usb_get_serial_port_data(port); |
---|
1220 | 797 | unsigned char data; |
---|
1221 | | - struct usb_serial *serial; |
---|
1222 | | - struct moschip_port *mos7840_port; |
---|
1223 | | - |
---|
1224 | | - if (mos7840_port_paranoia_check(port, __func__)) |
---|
1225 | | - return; |
---|
1226 | | - |
---|
1227 | | - serial = mos7840_get_usb_serial(port, __func__); |
---|
1228 | | - if (!serial) |
---|
1229 | | - return; |
---|
1230 | | - |
---|
1231 | | - mos7840_port = mos7840_get_port_private(port); |
---|
1232 | | - |
---|
1233 | | - if (mos7840_port == NULL) |
---|
1234 | | - return; |
---|
1235 | 798 | |
---|
1236 | 799 | if (break_state == -1) |
---|
1237 | 800 | data = mos7840_port->shadowLCR | LCR_SET_BREAK; |
---|
.. | .. |
---|
1256 | 819 | static int mos7840_write_room(struct tty_struct *tty) |
---|
1257 | 820 | { |
---|
1258 | 821 | struct usb_serial_port *port = tty->driver_data; |
---|
| 822 | + struct moschip_port *mos7840_port = usb_get_serial_port_data(port); |
---|
1259 | 823 | int i; |
---|
1260 | 824 | int room = 0; |
---|
1261 | 825 | unsigned long flags; |
---|
1262 | | - struct moschip_port *mos7840_port; |
---|
1263 | | - |
---|
1264 | | - if (mos7840_port_paranoia_check(port, __func__)) |
---|
1265 | | - return -1; |
---|
1266 | | - |
---|
1267 | | - mos7840_port = mos7840_get_port_private(port); |
---|
1268 | | - if (mos7840_port == NULL) |
---|
1269 | | - return -1; |
---|
1270 | 826 | |
---|
1271 | 827 | spin_lock_irqsave(&mos7840_port->pool_lock, flags); |
---|
1272 | 828 | for (i = 0; i < NUM_URBS; ++i) { |
---|
.. | .. |
---|
1292 | 848 | static int mos7840_write(struct tty_struct *tty, struct usb_serial_port *port, |
---|
1293 | 849 | const unsigned char *data, int count) |
---|
1294 | 850 | { |
---|
| 851 | + struct moschip_port *mos7840_port = usb_get_serial_port_data(port); |
---|
| 852 | + struct usb_serial *serial = port->serial; |
---|
1295 | 853 | int status; |
---|
1296 | 854 | int i; |
---|
1297 | 855 | int bytes_sent = 0; |
---|
1298 | 856 | int transfer_size; |
---|
1299 | 857 | unsigned long flags; |
---|
1300 | | - |
---|
1301 | | - struct moschip_port *mos7840_port; |
---|
1302 | | - struct usb_serial *serial; |
---|
1303 | 858 | struct urb *urb; |
---|
1304 | 859 | /* __u16 Data; */ |
---|
1305 | 860 | const unsigned char *current_position = data; |
---|
1306 | | - unsigned char *data1; |
---|
1307 | | - |
---|
1308 | | - if (mos7840_port_paranoia_check(port, __func__)) |
---|
1309 | | - return -1; |
---|
1310 | | - |
---|
1311 | | - serial = port->serial; |
---|
1312 | | - if (mos7840_serial_paranoia_check(serial, __func__)) |
---|
1313 | | - return -1; |
---|
1314 | | - |
---|
1315 | | - mos7840_port = mos7840_get_port_private(port); |
---|
1316 | | - if (mos7840_port == NULL) |
---|
1317 | | - return -1; |
---|
1318 | 861 | |
---|
1319 | 862 | /* try to find a free urb in the list */ |
---|
1320 | 863 | urb = NULL; |
---|
.. | .. |
---|
1366 | 909 | mos7840_bulk_out_data_callback, mos7840_port); |
---|
1367 | 910 | } |
---|
1368 | 911 | |
---|
1369 | | - data1 = urb->transfer_buffer; |
---|
1370 | 912 | dev_dbg(&port->dev, "bulkout endpoint is %d\n", port->bulk_out_endpointAddress); |
---|
1371 | 913 | |
---|
1372 | 914 | if (mos7840_port->has_led) |
---|
.. | .. |
---|
1399 | 941 | static void mos7840_throttle(struct tty_struct *tty) |
---|
1400 | 942 | { |
---|
1401 | 943 | struct usb_serial_port *port = tty->driver_data; |
---|
1402 | | - struct moschip_port *mos7840_port; |
---|
| 944 | + struct moschip_port *mos7840_port = usb_get_serial_port_data(port); |
---|
1403 | 945 | int status; |
---|
1404 | | - |
---|
1405 | | - if (mos7840_port_paranoia_check(port, __func__)) |
---|
1406 | | - return; |
---|
1407 | | - |
---|
1408 | | - mos7840_port = mos7840_get_port_private(port); |
---|
1409 | | - |
---|
1410 | | - if (mos7840_port == NULL) |
---|
1411 | | - return; |
---|
1412 | | - |
---|
1413 | | - if (!mos7840_port->open) { |
---|
1414 | | - dev_dbg(&port->dev, "%s", "port not opened\n"); |
---|
1415 | | - return; |
---|
1416 | | - } |
---|
1417 | 946 | |
---|
1418 | 947 | /* if we are implementing XON/XOFF, send the stop character */ |
---|
1419 | 948 | if (I_IXOFF(tty)) { |
---|
.. | .. |
---|
1441 | 970 | static void mos7840_unthrottle(struct tty_struct *tty) |
---|
1442 | 971 | { |
---|
1443 | 972 | struct usb_serial_port *port = tty->driver_data; |
---|
| 973 | + struct moschip_port *mos7840_port = usb_get_serial_port_data(port); |
---|
1444 | 974 | int status; |
---|
1445 | | - struct moschip_port *mos7840_port = mos7840_get_port_private(port); |
---|
1446 | | - |
---|
1447 | | - if (mos7840_port_paranoia_check(port, __func__)) |
---|
1448 | | - return; |
---|
1449 | | - |
---|
1450 | | - if (mos7840_port == NULL) |
---|
1451 | | - return; |
---|
1452 | | - |
---|
1453 | | - if (!mos7840_port->open) { |
---|
1454 | | - dev_dbg(&port->dev, "%s - port not opened\n", __func__); |
---|
1455 | | - return; |
---|
1456 | | - } |
---|
1457 | 975 | |
---|
1458 | 976 | /* if we are implementing XON/XOFF, send the start character */ |
---|
1459 | 977 | if (I_IXOFF(tty)) { |
---|
.. | .. |
---|
1476 | 994 | static int mos7840_tiocmget(struct tty_struct *tty) |
---|
1477 | 995 | { |
---|
1478 | 996 | struct usb_serial_port *port = tty->driver_data; |
---|
1479 | | - struct moschip_port *mos7840_port; |
---|
1480 | 997 | unsigned int result; |
---|
1481 | 998 | __u16 msr; |
---|
1482 | 999 | __u16 mcr; |
---|
1483 | 1000 | int status; |
---|
1484 | | - mos7840_port = mos7840_get_port_private(port); |
---|
1485 | | - |
---|
1486 | | - if (mos7840_port == NULL) |
---|
1487 | | - return -ENODEV; |
---|
1488 | 1001 | |
---|
1489 | 1002 | status = mos7840_get_uart_reg(port, MODEM_STATUS_REGISTER, &msr); |
---|
1490 | 1003 | if (status < 0) |
---|
.. | .. |
---|
1509 | 1022 | unsigned int set, unsigned int clear) |
---|
1510 | 1023 | { |
---|
1511 | 1024 | struct usb_serial_port *port = tty->driver_data; |
---|
1512 | | - struct moschip_port *mos7840_port; |
---|
| 1025 | + struct moschip_port *mos7840_port = usb_get_serial_port_data(port); |
---|
1513 | 1026 | unsigned int mcr; |
---|
1514 | 1027 | int status; |
---|
1515 | | - |
---|
1516 | | - mos7840_port = mos7840_get_port_private(port); |
---|
1517 | | - |
---|
1518 | | - if (mos7840_port == NULL) |
---|
1519 | | - return -ENODEV; |
---|
1520 | 1028 | |
---|
1521 | 1029 | /* FIXME: What locks the port registers ? */ |
---|
1522 | 1030 | mcr = mos7840_port->shadowMCR; |
---|
.. | .. |
---|
1594 | 1102 | static int mos7840_send_cmd_write_baud_rate(struct moschip_port *mos7840_port, |
---|
1595 | 1103 | int baudRate) |
---|
1596 | 1104 | { |
---|
| 1105 | + struct usb_serial_port *port = mos7840_port->port; |
---|
1597 | 1106 | int divisor = 0; |
---|
1598 | 1107 | int status; |
---|
1599 | 1108 | __u16 Data; |
---|
1600 | | - unsigned char number; |
---|
1601 | 1109 | __u16 clk_sel_val; |
---|
1602 | | - struct usb_serial_port *port; |
---|
1603 | | - |
---|
1604 | | - if (mos7840_port == NULL) |
---|
1605 | | - return -1; |
---|
1606 | | - |
---|
1607 | | - port = mos7840_port->port; |
---|
1608 | | - if (mos7840_port_paranoia_check(port, __func__)) |
---|
1609 | | - return -1; |
---|
1610 | | - |
---|
1611 | | - if (mos7840_serial_paranoia_check(port->serial, __func__)) |
---|
1612 | | - return -1; |
---|
1613 | | - |
---|
1614 | | - number = mos7840_port->port->port_number; |
---|
1615 | 1110 | |
---|
1616 | 1111 | dev_dbg(&port->dev, "%s - baud = %d\n", __func__, baudRate); |
---|
1617 | 1112 | /* reset clk_uart_sel in spregOffset */ |
---|
.. | .. |
---|
1700 | 1195 | static void mos7840_change_port_settings(struct tty_struct *tty, |
---|
1701 | 1196 | struct moschip_port *mos7840_port, struct ktermios *old_termios) |
---|
1702 | 1197 | { |
---|
| 1198 | + struct usb_serial_port *port = mos7840_port->port; |
---|
1703 | 1199 | int baud; |
---|
1704 | 1200 | unsigned cflag; |
---|
1705 | | - unsigned iflag; |
---|
1706 | 1201 | __u8 lData; |
---|
1707 | 1202 | __u8 lParity; |
---|
1708 | 1203 | __u8 lStop; |
---|
1709 | 1204 | int status; |
---|
1710 | 1205 | __u16 Data; |
---|
1711 | | - struct usb_serial_port *port; |
---|
1712 | | - struct usb_serial *serial; |
---|
1713 | | - |
---|
1714 | | - if (mos7840_port == NULL) |
---|
1715 | | - return; |
---|
1716 | | - |
---|
1717 | | - port = mos7840_port->port; |
---|
1718 | | - |
---|
1719 | | - if (mos7840_port_paranoia_check(port, __func__)) |
---|
1720 | | - return; |
---|
1721 | | - |
---|
1722 | | - if (mos7840_serial_paranoia_check(port->serial, __func__)) |
---|
1723 | | - return; |
---|
1724 | | - |
---|
1725 | | - serial = port->serial; |
---|
1726 | | - |
---|
1727 | | - if (!mos7840_port->open) { |
---|
1728 | | - dev_dbg(&port->dev, "%s - port not opened\n", __func__); |
---|
1729 | | - return; |
---|
1730 | | - } |
---|
1731 | 1206 | |
---|
1732 | 1207 | lData = LCR_BITS_8; |
---|
1733 | 1208 | lStop = LCR_STOP_1; |
---|
1734 | 1209 | lParity = LCR_PAR_NONE; |
---|
1735 | 1210 | |
---|
1736 | 1211 | cflag = tty->termios.c_cflag; |
---|
1737 | | - iflag = tty->termios.c_iflag; |
---|
1738 | 1212 | |
---|
1739 | 1213 | /* Change the number of bits */ |
---|
1740 | 1214 | switch (cflag & CSIZE) { |
---|
.. | .. |
---|
1863 | 1337 | struct usb_serial_port *port, |
---|
1864 | 1338 | struct ktermios *old_termios) |
---|
1865 | 1339 | { |
---|
| 1340 | + struct moschip_port *mos7840_port = usb_get_serial_port_data(port); |
---|
1866 | 1341 | int status; |
---|
1867 | | - struct usb_serial *serial; |
---|
1868 | | - struct moschip_port *mos7840_port; |
---|
1869 | | - |
---|
1870 | | - if (mos7840_port_paranoia_check(port, __func__)) |
---|
1871 | | - return; |
---|
1872 | | - |
---|
1873 | | - serial = port->serial; |
---|
1874 | | - |
---|
1875 | | - if (mos7840_serial_paranoia_check(serial, __func__)) |
---|
1876 | | - return; |
---|
1877 | | - |
---|
1878 | | - mos7840_port = mos7840_get_port_private(port); |
---|
1879 | | - |
---|
1880 | | - if (mos7840_port == NULL) |
---|
1881 | | - return; |
---|
1882 | | - |
---|
1883 | | - if (!mos7840_port->open) { |
---|
1884 | | - dev_dbg(&port->dev, "%s - port not opened\n", __func__); |
---|
1885 | | - return; |
---|
1886 | | - } |
---|
1887 | 1342 | |
---|
1888 | 1343 | /* change the port settings to the new ones specified */ |
---|
1889 | 1344 | |
---|
1890 | 1345 | mos7840_change_port_settings(tty, mos7840_port, old_termios); |
---|
1891 | | - |
---|
1892 | | - if (!mos7840_port->read_urb) { |
---|
1893 | | - dev_dbg(&port->dev, "%s", "URB KILLED !!!!!\n"); |
---|
1894 | | - return; |
---|
1895 | | - } |
---|
1896 | 1346 | |
---|
1897 | 1347 | if (!mos7840_port->read_urb_busy) { |
---|
1898 | 1348 | mos7840_port->read_urb_busy = true; |
---|
.. | .. |
---|
1936 | 1386 | * function to get information about serial port |
---|
1937 | 1387 | *****************************************************************************/ |
---|
1938 | 1388 | |
---|
1939 | | -static int mos7840_get_serial_info(struct moschip_port *mos7840_port, |
---|
1940 | | - struct serial_struct __user *retinfo) |
---|
| 1389 | +static int mos7840_get_serial_info(struct tty_struct *tty, |
---|
| 1390 | + struct serial_struct *ss) |
---|
1941 | 1391 | { |
---|
1942 | | - struct serial_struct tmp; |
---|
| 1392 | + struct usb_serial_port *port = tty->driver_data; |
---|
| 1393 | + struct moschip_port *mos7840_port = usb_get_serial_port_data(port); |
---|
1943 | 1394 | |
---|
1944 | | - if (mos7840_port == NULL) |
---|
1945 | | - return -1; |
---|
1946 | | - |
---|
1947 | | - memset(&tmp, 0, sizeof(tmp)); |
---|
1948 | | - |
---|
1949 | | - tmp.type = PORT_16550A; |
---|
1950 | | - tmp.line = mos7840_port->port->minor; |
---|
1951 | | - tmp.port = mos7840_port->port->port_number; |
---|
1952 | | - tmp.irq = 0; |
---|
1953 | | - tmp.xmit_fifo_size = NUM_URBS * URB_TRANSFER_BUFFER_SIZE; |
---|
1954 | | - tmp.baud_base = 9600; |
---|
1955 | | - tmp.close_delay = 5 * HZ; |
---|
1956 | | - tmp.closing_wait = 30 * HZ; |
---|
1957 | | - |
---|
1958 | | - if (copy_to_user(retinfo, &tmp, sizeof(*retinfo))) |
---|
1959 | | - return -EFAULT; |
---|
| 1395 | + ss->type = PORT_16550A; |
---|
| 1396 | + ss->line = mos7840_port->port->minor; |
---|
| 1397 | + ss->port = mos7840_port->port->port_number; |
---|
| 1398 | + ss->irq = 0; |
---|
| 1399 | + ss->xmit_fifo_size = NUM_URBS * URB_TRANSFER_BUFFER_SIZE; |
---|
| 1400 | + ss->baud_base = 9600; |
---|
| 1401 | + ss->close_delay = 5 * HZ; |
---|
| 1402 | + ss->closing_wait = 30 * HZ; |
---|
1960 | 1403 | return 0; |
---|
1961 | 1404 | } |
---|
1962 | 1405 | |
---|
.. | .. |
---|
1970 | 1413 | { |
---|
1971 | 1414 | struct usb_serial_port *port = tty->driver_data; |
---|
1972 | 1415 | void __user *argp = (void __user *)arg; |
---|
1973 | | - struct moschip_port *mos7840_port; |
---|
1974 | | - |
---|
1975 | | - if (mos7840_port_paranoia_check(port, __func__)) |
---|
1976 | | - return -1; |
---|
1977 | | - |
---|
1978 | | - mos7840_port = mos7840_get_port_private(port); |
---|
1979 | | - |
---|
1980 | | - if (mos7840_port == NULL) |
---|
1981 | | - return -1; |
---|
1982 | 1416 | |
---|
1983 | 1417 | switch (cmd) { |
---|
1984 | 1418 | /* return number of bytes available */ |
---|
.. | .. |
---|
1987 | 1421 | dev_dbg(&port->dev, "%s TIOCSERGETLSR\n", __func__); |
---|
1988 | 1422 | return mos7840_get_lsr_info(tty, argp); |
---|
1989 | 1423 | |
---|
1990 | | - case TIOCGSERIAL: |
---|
1991 | | - dev_dbg(&port->dev, "%s TIOCGSERIAL\n", __func__); |
---|
1992 | | - return mos7840_get_serial_info(mos7840_port, argp); |
---|
1993 | | - |
---|
1994 | | - case TIOCSSERIAL: |
---|
1995 | | - dev_dbg(&port->dev, "%s TIOCSSERIAL\n", __func__); |
---|
1996 | | - break; |
---|
1997 | 1424 | default: |
---|
1998 | 1425 | break; |
---|
1999 | 1426 | } |
---|
2000 | 1427 | return -ENOIOCTLCMD; |
---|
2001 | 1428 | } |
---|
2002 | 1429 | |
---|
| 1430 | +/* |
---|
| 1431 | + * Check if GPO (pin 42) is connected to GPI (pin 33) as recommended by ASIX |
---|
| 1432 | + * for MCS7810 by bit-banging a 16-bit word. |
---|
| 1433 | + * |
---|
| 1434 | + * Note that GPO is really RTS of the third port so this will toggle RTS of |
---|
| 1435 | + * port two or three on two- and four-port devices. |
---|
| 1436 | + */ |
---|
2003 | 1437 | static int mos7810_check(struct usb_serial *serial) |
---|
2004 | 1438 | { |
---|
2005 | 1439 | int i, pass_count = 0; |
---|
.. | .. |
---|
2057 | 1491 | static int mos7840_probe(struct usb_serial *serial, |
---|
2058 | 1492 | const struct usb_device_id *id) |
---|
2059 | 1493 | { |
---|
2060 | | - u16 product = le16_to_cpu(serial->dev->descriptor.idProduct); |
---|
2061 | | - u16 vid = le16_to_cpu(serial->dev->descriptor.idVendor); |
---|
| 1494 | + unsigned long device_flags = id->driver_info; |
---|
2062 | 1495 | u8 *buf; |
---|
2063 | | - int device_type; |
---|
2064 | 1496 | |
---|
2065 | | - if (product == MOSCHIP_DEVICE_ID_7810 || |
---|
2066 | | - product == MOSCHIP_DEVICE_ID_7820) { |
---|
2067 | | - device_type = product; |
---|
| 1497 | + /* Skip device-type detection if we already have device flags. */ |
---|
| 1498 | + if (device_flags) |
---|
2068 | 1499 | goto out; |
---|
2069 | | - } |
---|
2070 | | - |
---|
2071 | | - if (vid == USB_VENDOR_ID_MOXA && product == MOXA_DEVICE_ID_2210) { |
---|
2072 | | - device_type = MOSCHIP_DEVICE_ID_7820; |
---|
2073 | | - goto out; |
---|
2074 | | - } |
---|
2075 | 1500 | |
---|
2076 | 1501 | buf = kzalloc(VENDOR_READ_LENGTH, GFP_KERNEL); |
---|
2077 | 1502 | if (!buf) |
---|
.. | .. |
---|
2083 | 1508 | |
---|
2084 | 1509 | /* For a MCS7840 device GPIO0 must be set to 1 */ |
---|
2085 | 1510 | if (buf[0] & 0x01) |
---|
2086 | | - device_type = MOSCHIP_DEVICE_ID_7840; |
---|
| 1511 | + device_flags = MCS_PORTS(4); |
---|
2087 | 1512 | else if (mos7810_check(serial)) |
---|
2088 | | - device_type = MOSCHIP_DEVICE_ID_7810; |
---|
| 1513 | + device_flags = MCS_PORTS(1) | MCS_LED; |
---|
2089 | 1514 | else |
---|
2090 | | - device_type = MOSCHIP_DEVICE_ID_7820; |
---|
| 1515 | + device_flags = MCS_PORTS(2); |
---|
2091 | 1516 | |
---|
2092 | 1517 | kfree(buf); |
---|
2093 | 1518 | out: |
---|
2094 | | - usb_set_serial_data(serial, (void *)(unsigned long)device_type); |
---|
| 1519 | + usb_set_serial_data(serial, (void *)device_flags); |
---|
2095 | 1520 | |
---|
2096 | 1521 | return 0; |
---|
2097 | 1522 | } |
---|
.. | .. |
---|
2099 | 1524 | static int mos7840_calc_num_ports(struct usb_serial *serial, |
---|
2100 | 1525 | struct usb_serial_endpoints *epds) |
---|
2101 | 1526 | { |
---|
2102 | | - int device_type = (unsigned long)usb_get_serial_data(serial); |
---|
2103 | | - int num_ports; |
---|
| 1527 | + unsigned long device_flags = (unsigned long)usb_get_serial_data(serial); |
---|
| 1528 | + int num_ports = MCS_PORTS(device_flags); |
---|
2104 | 1529 | |
---|
2105 | | - num_ports = (device_type >> 4) & 0x000F; |
---|
2106 | | - |
---|
2107 | | - /* |
---|
2108 | | - * num_ports is currently never zero as device_type is one of |
---|
2109 | | - * MOSCHIP_DEVICE_ID_78{1,2,4}0. |
---|
2110 | | - */ |
---|
2111 | | - if (num_ports == 0) |
---|
| 1530 | + if (num_ports == 0 || num_ports > 4) |
---|
2112 | 1531 | return -ENODEV; |
---|
2113 | 1532 | |
---|
2114 | 1533 | if (epds->num_bulk_in < num_ports || epds->num_bulk_out < num_ports) { |
---|
.. | .. |
---|
2119 | 1538 | return num_ports; |
---|
2120 | 1539 | } |
---|
2121 | 1540 | |
---|
| 1541 | +static int mos7840_attach(struct usb_serial *serial) |
---|
| 1542 | +{ |
---|
| 1543 | + struct device *dev = &serial->interface->dev; |
---|
| 1544 | + int status; |
---|
| 1545 | + u16 val; |
---|
| 1546 | + |
---|
| 1547 | + /* Zero Length flag enable */ |
---|
| 1548 | + val = 0x0f; |
---|
| 1549 | + status = mos7840_set_reg_sync(serial->port[0], ZLP_REG5, val); |
---|
| 1550 | + if (status < 0) |
---|
| 1551 | + dev_dbg(dev, "Writing ZLP_REG5 failed status-0x%x\n", status); |
---|
| 1552 | + else |
---|
| 1553 | + dev_dbg(dev, "ZLP_REG5 Writing success status%d\n", status); |
---|
| 1554 | + |
---|
| 1555 | + return status; |
---|
| 1556 | +} |
---|
| 1557 | + |
---|
2122 | 1558 | static int mos7840_port_probe(struct usb_serial_port *port) |
---|
2123 | 1559 | { |
---|
2124 | 1560 | struct usb_serial *serial = port->serial; |
---|
2125 | | - int device_type = (unsigned long)usb_get_serial_data(serial); |
---|
| 1561 | + unsigned long device_flags = (unsigned long)usb_get_serial_data(serial); |
---|
2126 | 1562 | struct moschip_port *mos7840_port; |
---|
2127 | 1563 | int status; |
---|
2128 | 1564 | int pnum; |
---|
.. | .. |
---|
2143 | 1579 | * common to all port */ |
---|
2144 | 1580 | |
---|
2145 | 1581 | mos7840_port->port = port; |
---|
2146 | | - mos7840_set_port_private(port, mos7840_port); |
---|
2147 | 1582 | spin_lock_init(&mos7840_port->pool_lock); |
---|
2148 | 1583 | |
---|
2149 | 1584 | /* minor is not initialised until later by |
---|
.. | .. |
---|
2157 | 1592 | mos7840_port->SpRegOffset = 0x0; |
---|
2158 | 1593 | mos7840_port->ControlRegOffset = 0x1; |
---|
2159 | 1594 | mos7840_port->DcrRegOffset = 0x4; |
---|
2160 | | - } else if ((mos7840_port->port_num == 2) && (serial->num_ports == 4)) { |
---|
2161 | | - mos7840_port->SpRegOffset = 0x8; |
---|
2162 | | - mos7840_port->ControlRegOffset = 0x9; |
---|
2163 | | - mos7840_port->DcrRegOffset = 0x16; |
---|
2164 | | - } else if ((mos7840_port->port_num == 2) && (serial->num_ports == 2)) { |
---|
2165 | | - mos7840_port->SpRegOffset = 0xa; |
---|
2166 | | - mos7840_port->ControlRegOffset = 0xb; |
---|
2167 | | - mos7840_port->DcrRegOffset = 0x19; |
---|
2168 | | - } else if ((mos7840_port->port_num == 3) && (serial->num_ports == 4)) { |
---|
2169 | | - mos7840_port->SpRegOffset = 0xa; |
---|
2170 | | - mos7840_port->ControlRegOffset = 0xb; |
---|
2171 | | - mos7840_port->DcrRegOffset = 0x19; |
---|
2172 | | - } else if ((mos7840_port->port_num == 4) && (serial->num_ports == 4)) { |
---|
2173 | | - mos7840_port->SpRegOffset = 0xc; |
---|
2174 | | - mos7840_port->ControlRegOffset = 0xd; |
---|
2175 | | - mos7840_port->DcrRegOffset = 0x1c; |
---|
| 1595 | + } else { |
---|
| 1596 | + u8 phy_num = mos7840_port->port_num; |
---|
| 1597 | + |
---|
| 1598 | + /* Port 2 in the 2-port case uses registers of port 3 */ |
---|
| 1599 | + if (serial->num_ports == 2) |
---|
| 1600 | + phy_num = 3; |
---|
| 1601 | + |
---|
| 1602 | + mos7840_port->SpRegOffset = 0x8 + 2 * (phy_num - 2); |
---|
| 1603 | + mos7840_port->ControlRegOffset = 0x9 + 2 * (phy_num - 2); |
---|
| 1604 | + mos7840_port->DcrRegOffset = 0x16 + 3 * (phy_num - 2); |
---|
2176 | 1605 | } |
---|
2177 | 1606 | mos7840_dump_serial_port(port, mos7840_port); |
---|
2178 | | - mos7840_set_port_private(port, mos7840_port); |
---|
| 1607 | + usb_set_serial_port_data(port, mos7840_port); |
---|
2179 | 1608 | |
---|
2180 | 1609 | /* enable rx_disable bit in control register */ |
---|
2181 | 1610 | status = mos7840_get_reg_sync(port, |
---|
2182 | 1611 | mos7840_port->ControlRegOffset, &Data); |
---|
2183 | 1612 | if (status < 0) { |
---|
2184 | 1613 | dev_dbg(&port->dev, "Reading ControlReg failed status-0x%x\n", status); |
---|
2185 | | - goto out; |
---|
| 1614 | + goto error; |
---|
2186 | 1615 | } else |
---|
2187 | 1616 | dev_dbg(&port->dev, "ControlReg Reading success val is %x, status%d\n", Data, status); |
---|
2188 | 1617 | Data |= 0x08; /* setting driver done bit */ |
---|
.. | .. |
---|
2194 | 1623 | mos7840_port->ControlRegOffset, Data); |
---|
2195 | 1624 | if (status < 0) { |
---|
2196 | 1625 | dev_dbg(&port->dev, "Writing ControlReg failed(rx_disable) status-0x%x\n", status); |
---|
2197 | | - goto out; |
---|
| 1626 | + goto error; |
---|
2198 | 1627 | } else |
---|
2199 | 1628 | dev_dbg(&port->dev, "ControlReg Writing success(rx_disable) status%d\n", status); |
---|
2200 | 1629 | |
---|
.. | .. |
---|
2205 | 1634 | (__u16) (mos7840_port->DcrRegOffset + 0), Data); |
---|
2206 | 1635 | if (status < 0) { |
---|
2207 | 1636 | dev_dbg(&port->dev, "Writing DCR0 failed status-0x%x\n", status); |
---|
2208 | | - goto out; |
---|
| 1637 | + goto error; |
---|
2209 | 1638 | } else |
---|
2210 | 1639 | dev_dbg(&port->dev, "DCR0 Writing success status%d\n", status); |
---|
2211 | 1640 | |
---|
.. | .. |
---|
2214 | 1643 | (__u16) (mos7840_port->DcrRegOffset + 1), Data); |
---|
2215 | 1644 | if (status < 0) { |
---|
2216 | 1645 | dev_dbg(&port->dev, "Writing DCR1 failed status-0x%x\n", status); |
---|
2217 | | - goto out; |
---|
| 1646 | + goto error; |
---|
2218 | 1647 | } else |
---|
2219 | 1648 | dev_dbg(&port->dev, "DCR1 Writing success status%d\n", status); |
---|
2220 | 1649 | |
---|
.. | .. |
---|
2223 | 1652 | (__u16) (mos7840_port->DcrRegOffset + 2), Data); |
---|
2224 | 1653 | if (status < 0) { |
---|
2225 | 1654 | dev_dbg(&port->dev, "Writing DCR2 failed status-0x%x\n", status); |
---|
2226 | | - goto out; |
---|
| 1655 | + goto error; |
---|
2227 | 1656 | } else |
---|
2228 | 1657 | dev_dbg(&port->dev, "DCR2 Writing success status%d\n", status); |
---|
2229 | 1658 | |
---|
.. | .. |
---|
2232 | 1661 | status = mos7840_set_reg_sync(port, CLK_START_VALUE_REGISTER, Data); |
---|
2233 | 1662 | if (status < 0) { |
---|
2234 | 1663 | dev_dbg(&port->dev, "Writing CLK_START_VALUE_REGISTER failed status-0x%x\n", status); |
---|
2235 | | - goto out; |
---|
| 1664 | + goto error; |
---|
2236 | 1665 | } else |
---|
2237 | 1666 | dev_dbg(&port->dev, "CLK_START_VALUE_REGISTER Writing success status%d\n", status); |
---|
2238 | 1667 | |
---|
.. | .. |
---|
2249 | 1678 | status = mos7840_set_uart_reg(port, SCRATCH_PAD_REGISTER, Data); |
---|
2250 | 1679 | if (status < 0) { |
---|
2251 | 1680 | dev_dbg(&port->dev, "Writing SCRATCH_PAD_REGISTER failed status-0x%x\n", status); |
---|
2252 | | - goto out; |
---|
| 1681 | + goto error; |
---|
2253 | 1682 | } else |
---|
2254 | 1683 | dev_dbg(&port->dev, "SCRATCH_PAD_REGISTER Writing success status%d\n", status); |
---|
2255 | 1684 | |
---|
.. | .. |
---|
2263 | 1692 | (__u16)(ZLP_REG1 + ((__u16) mos7840_port->port_num))); |
---|
2264 | 1693 | if (status < 0) { |
---|
2265 | 1694 | dev_dbg(&port->dev, "Writing ZLP_REG%d failed status-0x%x\n", pnum + 2, status); |
---|
2266 | | - goto out; |
---|
| 1695 | + goto error; |
---|
2267 | 1696 | } else |
---|
2268 | 1697 | dev_dbg(&port->dev, "ZLP_REG%d Writing success status%d\n", pnum + 2, status); |
---|
2269 | 1698 | } else { |
---|
.. | .. |
---|
2275 | 1704 | (__u16)(ZLP_REG1 + ((__u16) mos7840_port->port_num) - 0x1)); |
---|
2276 | 1705 | if (status < 0) { |
---|
2277 | 1706 | dev_dbg(&port->dev, "Writing ZLP_REG%d failed status-0x%x\n", pnum + 1, status); |
---|
2278 | | - goto out; |
---|
| 1707 | + goto error; |
---|
2279 | 1708 | } else |
---|
2280 | 1709 | dev_dbg(&port->dev, "ZLP_REG%d Writing success status%d\n", pnum + 1, status); |
---|
2281 | 1710 | |
---|
2282 | 1711 | } |
---|
2283 | | - mos7840_port->control_urb = usb_alloc_urb(0, GFP_KERNEL); |
---|
2284 | | - mos7840_port->ctrl_buf = kmalloc(16, GFP_KERNEL); |
---|
2285 | | - mos7840_port->dr = kmalloc(sizeof(struct usb_ctrlrequest), |
---|
2286 | | - GFP_KERNEL); |
---|
2287 | | - if (!mos7840_port->control_urb || !mos7840_port->ctrl_buf || |
---|
2288 | | - !mos7840_port->dr) { |
---|
2289 | | - status = -ENOMEM; |
---|
2290 | | - goto error; |
---|
2291 | | - } |
---|
2292 | 1712 | |
---|
2293 | | - mos7840_port->has_led = false; |
---|
| 1713 | + mos7840_port->has_led = device_flags & MCS_LED; |
---|
2294 | 1714 | |
---|
2295 | 1715 | /* Initialize LED timers */ |
---|
2296 | | - if (device_type == MOSCHIP_DEVICE_ID_7810) { |
---|
2297 | | - mos7840_port->has_led = true; |
---|
2298 | | - |
---|
| 1716 | + if (mos7840_port->has_led) { |
---|
2299 | 1717 | mos7840_port->led_urb = usb_alloc_urb(0, GFP_KERNEL); |
---|
2300 | 1718 | mos7840_port->led_dr = kmalloc(sizeof(*mos7840_port->led_dr), |
---|
2301 | 1719 | GFP_KERNEL); |
---|
.. | .. |
---|
2315 | 1733 | /* Turn off LED */ |
---|
2316 | 1734 | mos7840_set_led_sync(port, MODEM_CONTROL_REGISTER, 0x0300); |
---|
2317 | 1735 | } |
---|
2318 | | -out: |
---|
2319 | | - if (pnum == serial->num_ports - 1) { |
---|
2320 | | - /* Zero Length flag enable */ |
---|
2321 | | - Data = 0x0f; |
---|
2322 | | - status = mos7840_set_reg_sync(serial->port[0], ZLP_REG5, Data); |
---|
2323 | | - if (status < 0) { |
---|
2324 | | - dev_dbg(&port->dev, "Writing ZLP_REG5 failed status-0x%x\n", status); |
---|
2325 | | - goto error; |
---|
2326 | | - } else |
---|
2327 | | - dev_dbg(&port->dev, "ZLP_REG5 Writing success status%d\n", status); |
---|
2328 | | - } |
---|
| 1736 | + |
---|
2329 | 1737 | return 0; |
---|
2330 | 1738 | error: |
---|
2331 | 1739 | kfree(mos7840_port->led_dr); |
---|
2332 | 1740 | usb_free_urb(mos7840_port->led_urb); |
---|
2333 | | - kfree(mos7840_port->dr); |
---|
2334 | | - kfree(mos7840_port->ctrl_buf); |
---|
2335 | | - usb_free_urb(mos7840_port->control_urb); |
---|
2336 | 1741 | kfree(mos7840_port); |
---|
2337 | 1742 | |
---|
2338 | 1743 | return status; |
---|
.. | .. |
---|
2340 | 1745 | |
---|
2341 | 1746 | static int mos7840_port_remove(struct usb_serial_port *port) |
---|
2342 | 1747 | { |
---|
2343 | | - struct moschip_port *mos7840_port; |
---|
2344 | | - |
---|
2345 | | - mos7840_port = mos7840_get_port_private(port); |
---|
| 1748 | + struct moschip_port *mos7840_port = usb_get_serial_port_data(port); |
---|
2346 | 1749 | |
---|
2347 | 1750 | if (mos7840_port->has_led) { |
---|
2348 | 1751 | /* Turn off LED */ |
---|
.. | .. |
---|
2355 | 1758 | usb_free_urb(mos7840_port->led_urb); |
---|
2356 | 1759 | kfree(mos7840_port->led_dr); |
---|
2357 | 1760 | } |
---|
2358 | | - usb_kill_urb(mos7840_port->control_urb); |
---|
2359 | | - usb_free_urb(mos7840_port->control_urb); |
---|
2360 | | - kfree(mos7840_port->ctrl_buf); |
---|
2361 | | - kfree(mos7840_port->dr); |
---|
| 1761 | + |
---|
2362 | 1762 | kfree(mos7840_port); |
---|
2363 | 1763 | |
---|
2364 | 1764 | return 0; |
---|
.. | .. |
---|
2381 | 1781 | .unthrottle = mos7840_unthrottle, |
---|
2382 | 1782 | .calc_num_ports = mos7840_calc_num_ports, |
---|
2383 | 1783 | .probe = mos7840_probe, |
---|
| 1784 | + .attach = mos7840_attach, |
---|
2384 | 1785 | .ioctl = mos7840_ioctl, |
---|
| 1786 | + .get_serial = mos7840_get_serial_info, |
---|
2385 | 1787 | .set_termios = mos7840_set_termios, |
---|
2386 | 1788 | .break_ctl = mos7840_break, |
---|
2387 | 1789 | .tiocmget = mos7840_tiocmget, |
---|
2388 | 1790 | .tiocmset = mos7840_tiocmset, |
---|
2389 | | - .tiocmiwait = usb_serial_generic_tiocmiwait, |
---|
2390 | 1791 | .get_icount = usb_serial_generic_get_icount, |
---|
2391 | 1792 | .port_probe = mos7840_port_probe, |
---|
2392 | 1793 | .port_remove = mos7840_port_remove, |
---|
2393 | 1794 | .read_bulk_callback = mos7840_bulk_in_callback, |
---|
2394 | | - .read_int_callback = mos7840_interrupt_callback, |
---|
2395 | 1795 | }; |
---|
2396 | 1796 | |
---|
2397 | 1797 | static struct usb_serial_driver * const serial_drivers[] = { |
---|