提交 a9ea2266 编写于 作者: G Greg Kroah-Hartman

Staging: serqt_usb: Lindent the code

Run Lindent on the code to give us someplace to work from
Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
上级 5ca0121f
...@@ -20,16 +20,14 @@ ...@@ -20,16 +20,14 @@
//#define DEBUG_ON //#define DEBUG_ON
//#undef dbg //#undef dbg
#ifdef DEBUG_ON #ifdef DEBUG_ON
#define mydbg(const...) printk(const) #define mydbg(const...) printk(const)
#else #else
#define mydbg(const...) #define mydbg(const...)
#endif #endif
/* parity check flag */ /* parity check flag */
#define RELEVANT_IFLAG(iflag) (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK)) #define RELEVANT_IFLAG(iflag) (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK))
#define SERIAL_TTY_MAJOR 0 /* Nice legal number now */ #define SERIAL_TTY_MAJOR 0 /* Nice legal number now */
#define SERIAL_TTY_MINORS 255 /* loads of devices :) */ #define SERIAL_TTY_MINORS 255 /* loads of devices :) */
#define MAX_NUM_PORTS 8 /* The maximum number of ports one device can grab at once */ #define MAX_NUM_PORTS 8 /* The maximum number of ports one device can grab at once */
...@@ -47,7 +45,6 @@ ...@@ -47,7 +45,6 @@
#define ALL_LOOPBACK 0x01 #define ALL_LOOPBACK 0x01
#define MODEM_CTRL 0x40 #define MODEM_CTRL 0x40
#define THISCHAR data[i] #define THISCHAR data[i]
#define NEXTCHAR data[i + 1] #define NEXTCHAR data[i + 1]
#define THIRDCHAR data[i + 2] #define THIRDCHAR data[i + 2]
...@@ -58,7 +55,6 @@ ...@@ -58,7 +55,6 @@
#define FULLPWRBIT 0x00000080 #define FULLPWRBIT 0x00000080
#define NEXT_BOARD_POWER_BIT 0x00000004 #define NEXT_BOARD_POWER_BIT 0x00000004
#define SERIAL_LSR_OE 0x02 #define SERIAL_LSR_OE 0x02
#define SERIAL_LSR_PE 0x04 #define SERIAL_LSR_PE 0x04
#define SERIAL_LSR_FE 0x08 #define SERIAL_LSR_FE 0x08
...@@ -76,7 +72,6 @@ ...@@ -76,7 +72,6 @@
#define LINE_STATUS_REGISTER 0x05 #define LINE_STATUS_REGISTER 0x05
#define MODEM_STATUS_REGISTER 0x06 #define MODEM_STATUS_REGISTER 0x06
#define SERIAL_MCR_DTR 0x01 #define SERIAL_MCR_DTR 0x01
#define SERIAL_MCR_RTS 0x02 #define SERIAL_MCR_RTS 0x02
#define SERIAL_MCR_LOOP 0x10 #define SERIAL_MCR_LOOP 0x10
...@@ -100,7 +95,6 @@ ...@@ -100,7 +95,6 @@
#define MAX_BAUD_RATE 460800 #define MAX_BAUD_RATE 460800
#define MAX_BAUD_REMAINDER 4608 #define MAX_BAUD_REMAINDER 4608
#define QT_SET_GET_DEVICE 0xc2 #define QT_SET_GET_DEVICE 0xc2
#define QT_OPEN_CLOSE_CHANNEL 0xca #define QT_OPEN_CLOSE_CHANNEL 0xca
#define QT_GET_SET_PREBUF_TRIG_LVL 0xcc #define QT_GET_SET_PREBUF_TRIG_LVL 0xcc
...@@ -121,7 +115,6 @@ ...@@ -121,7 +115,6 @@
#define SERIALQT_READ_QMCR _IOR(SERIALQT_PCI_IOC_MAGIC, 5, int) #define SERIALQT_READ_QMCR _IOR(SERIALQT_PCI_IOC_MAGIC, 5, int)
#define SERIALQT_IS422_EXTENDED _IOR(SERIALQT_PCI_IOC_MAGIC, 6, int) //returns successful if 422 extended #define SERIALQT_IS422_EXTENDED _IOR(SERIALQT_PCI_IOC_MAGIC, 6, int) //returns successful if 422 extended
#define USBD_TRANSFER_DIRECTION_IN 0xc0 #define USBD_TRANSFER_DIRECTION_IN 0xc0
#define USBD_TRANSFER_DIRECTION_OUT 0x40 #define USBD_TRANSFER_DIRECTION_OUT 0x40
...@@ -147,28 +140,26 @@ ...@@ -147,28 +140,26 @@
#define QMCR_ALL_LOOPBACK 0x10 #define QMCR_ALL_LOOPBACK 0x10
#define QMCR_MODEM_CONTROL 0X00 #define QMCR_MODEM_CONTROL 0X00
#define SERIALQT_IOC_MAXNR 6 #define SERIALQT_IOC_MAXNR 6
struct usb_serial_port { struct usb_serial_port {
struct usb_serial *serial; /* pointer back to the owner of this port */ struct usb_serial *serial; /* pointer back to the owner of this port */
struct tty_struct * tty; /* the coresponding tty for this port */ struct tty_struct *tty; /* the coresponding tty for this port */
unsigned char number; unsigned char number;
char active; /* someone has this device open */ char active; /* someone has this device open */
unsigned char * interrupt_in_buffer; unsigned char *interrupt_in_buffer;
struct urb * interrupt_in_urb; struct urb *interrupt_in_urb;
__u8 interrupt_in_endpointAddress; __u8 interrupt_in_endpointAddress;
unsigned char * bulk_in_buffer; unsigned char *bulk_in_buffer;
unsigned char * xfer_to_tty_buffer; unsigned char *xfer_to_tty_buffer;
struct urb * read_urb; struct urb *read_urb;
__u8 bulk_in_endpointAddress; __u8 bulk_in_endpointAddress;
unsigned char * bulk_out_buffer; unsigned char *bulk_out_buffer;
int bulk_out_size; int bulk_out_size;
struct urb * write_urb; struct urb *write_urb;
__u8 bulk_out_endpointAddress; __u8 bulk_out_endpointAddress;
wait_queue_head_t write_wait; wait_queue_head_t write_wait;
...@@ -186,7 +177,7 @@ struct usb_serial_port { ...@@ -186,7 +177,7 @@ struct usb_serial_port {
char closePending; char closePending;
int ReadBulkStopped; int ReadBulkStopped;
void * private; /* data private to the specific port */ void *private; /* data private to the specific port */
}; };
struct identity { struct identity {
...@@ -195,9 +186,9 @@ struct identity { ...@@ -195,9 +186,9 @@ struct identity {
}; };
struct usb_serial { struct usb_serial {
struct usb_device * dev; struct usb_device *dev;
struct usb_interface * interface; /* the interface for this device */ struct usb_interface *interface; /* the interface for this device */
struct tty_driver * tty_driver; /* the tty_driver for this device */ struct tty_driver *tty_driver; /* the tty_driver for this device */
unsigned char minor; /* the starting minor number for this device */ unsigned char minor; /* the starting minor number for this device */
unsigned char num_ports; /* the number of ports this device has */ unsigned char num_ports; /* the number of ports this device has */
char num_interrupt_in; /* number of interrupt in endpoints we have */ char num_interrupt_in; /* number of interrupt in endpoints we have */
...@@ -205,17 +196,15 @@ struct usb_serial { ...@@ -205,17 +196,15 @@ struct usb_serial {
char num_bulk_out; /* number of bulk out endpoints we have */ char num_bulk_out; /* number of bulk out endpoints we have */
unsigned char num_OpenCount; /* the number of ports this device has */ unsigned char num_OpenCount; /* the number of ports this device has */
__u16 vendor; /* vendor id of this device */ __u16 vendor; /* vendor id of this device */
__u16 product; /* product id of this device */ __u16 product; /* product id of this device */
struct usb_serial_port port[MAX_NUM_PORTS]; struct usb_serial_port port[MAX_NUM_PORTS];
void * private; /* data private to the specific driver */ void *private; /* data private to the specific driver */
}; };
static inline int port_paranoia_check(struct usb_serial_port *port,
const char *function)
static inline int port_paranoia_check (struct usb_serial_port *port, const char *function)
{ {
if (!port) { if (!port) {
dbg("%s - port == NULL", function); dbg("%s - port == NULL", function);
...@@ -233,9 +222,9 @@ static inline int port_paranoia_check (struct usb_serial_port *port, const char ...@@ -233,9 +222,9 @@ static inline int port_paranoia_check (struct usb_serial_port *port, const char
return 0; return 0;
} }
/* Inline functions to check the sanity of a pointer that is passed to us */ /* Inline functions to check the sanity of a pointer that is passed to us */
static inline int serial_paranoia_check (struct usb_serial *serial, const char *function) static inline int serial_paranoia_check(struct usb_serial *serial,
const char *function)
{ {
if (!serial) { if (!serial) {
dbg("%s - serial == NULL\n", function); dbg("%s - serial == NULL\n", function);
...@@ -245,13 +234,13 @@ static inline int serial_paranoia_check (struct usb_serial *serial, const char * ...@@ -245,13 +234,13 @@ static inline int serial_paranoia_check (struct usb_serial *serial, const char *
return 0; return 0;
} }
static inline struct usb_serial *get_usb_serial(struct usb_serial_port *port,
static inline struct usb_serial* get_usb_serial (struct usb_serial_port *port, const char *function) const char *function)
{ {
/* if no port was specified, or it fails a paranoia check */ /* if no port was specified, or it fails a paranoia check */
if (!port || if (!port ||
port_paranoia_check (port, function) || port_paranoia_check(port, function) ||
serial_paranoia_check (port->serial, function)) { serial_paranoia_check(port->serial, function)) {
/* then say that we dont have a valid usb_serial thing, which will /* then say that we dont have a valid usb_serial thing, which will
* end up genrating -ENODEV return values */ * end up genrating -ENODEV return values */
return NULL; return NULL;
...@@ -260,90 +249,99 @@ static inline struct usb_serial* get_usb_serial (struct usb_serial_port *port, c ...@@ -260,90 +249,99 @@ static inline struct usb_serial* get_usb_serial (struct usb_serial_port *port, c
return port->serial; return port->serial;
} }
struct qt_get_device_data {
struct qt_get_device_data
{
__u8 porta; __u8 porta;
__u8 portb; __u8 portb;
__u8 portc; __u8 portc;
}; };
struct qt_open_channel_data struct qt_open_channel_data {
{
__u8 line_status; __u8 line_status;
__u8 modem_status; __u8 modem_status;
}; };
static void ProcessLineStatus(struct usb_serial_port *port, unsigned char line_status); static void ProcessLineStatus(struct usb_serial_port *port,
static void ProcessModemStatus(struct usb_serial_port *port, unsigned char modem_status); unsigned char line_status);
static void ProcessModemStatus(struct usb_serial_port *port,
unsigned char modem_status);
static void ProcessRxChar(struct usb_serial_port *port, unsigned char Data); static void ProcessRxChar(struct usb_serial_port *port, unsigned char Data);
static struct usb_serial *get_free_serial (int num_ports, int *minor); static struct usb_serial *get_free_serial(int num_ports, int *minor);
static int serqt_probe(struct usb_interface *interface, static int serqt_probe(struct usb_interface *interface,
const struct usb_device_id *id); const struct usb_device_id *id);
static void serqt_usb_disconnect(struct usb_interface *interface); static void serqt_usb_disconnect(struct usb_interface *interface);
static int box_set_device(struct usb_serial *serial, struct qt_get_device_data *pDeviceData); static int box_set_device(struct usb_serial *serial,
static int box_get_device(struct usb_serial *serial, struct qt_get_device_data *pDeviceData); struct qt_get_device_data *pDeviceData);
static int serial_open (struct tty_struct *tty, struct file * filp); static int box_get_device(struct usb_serial *serial,
static void serial_close(struct tty_struct *tty, struct file * filp); struct qt_get_device_data *pDeviceData);
static int serial_write_room (struct tty_struct *tty); static int serial_open(struct tty_struct *tty, struct file *filp);
static int serial_ioctl (struct tty_struct *tty, struct file * file, unsigned int cmd, unsigned long arg); static void serial_close(struct tty_struct *tty, struct file *filp);
static void serial_set_termios (struct tty_struct *tty, struct ktermios * old); static int serial_write_room(struct tty_struct *tty);
static int serial_write (struct tty_struct * tty, const unsigned char *buf, int count); static int serial_ioctl(struct tty_struct *tty, struct file *file,
unsigned int cmd, unsigned long arg);
static void serial_throttle (struct tty_struct * tty); static void serial_set_termios(struct tty_struct *tty, struct ktermios *old);
static void serial_unthrottle (struct tty_struct * tty); static int serial_write(struct tty_struct *tty, const unsigned char *buf,
static int serial_break (struct tty_struct *tty, int break_state); int count);
static int serial_chars_in_buffer (struct tty_struct *tty);
static int serial_read_proc (char *page, char **start, off_t off, int count, int *eof, void *data); static void serial_throttle(struct tty_struct *tty);
static void serial_unthrottle(struct tty_struct *tty);
static int qt_open (struct usb_serial_port *port, struct file *filp); static int serial_break(struct tty_struct *tty, int break_state);
static int serial_chars_in_buffer(struct tty_struct *tty);
static int serial_read_proc(char *page, char **start, off_t off, int count,
int *eof, void *data);
static int qt_open(struct usb_serial_port *port, struct file *filp);
static int BoxSetPrebufferLevel(struct usb_serial *serial); static int BoxSetPrebufferLevel(struct usb_serial *serial);
static int BoxSetATC(struct usb_serial *serial, __u16 n_Mode); static int BoxSetATC(struct usb_serial *serial, __u16 n_Mode);
static int BoxSetUart(struct usb_serial *serial, unsigned short Uart_Number, unsigned short default_divisor, unsigned char default_LCR ); static int BoxSetUart(struct usb_serial *serial, unsigned short Uart_Number,
unsigned short default_divisor,
unsigned char default_LCR);
static int BoxOPenCloseChannel(struct usb_serial *serial, __u16 Uart_Number, __u16 OpenClose, struct qt_open_channel_data *pDeviceData); static int BoxOPenCloseChannel(struct usb_serial *serial, __u16 Uart_Number,
static void qt_close (struct usb_serial_port *port, struct file * filp); __u16 OpenClose,
static int BoxGetRegister(struct usb_serial *serial, unsigned short Uart_Number,unsigned short Register_Num, __u8 *pValue); struct qt_open_channel_data *pDeviceData);
static int BoxSetRegister(struct usb_serial *serial, unsigned short Uart_Number, unsigned short Register_Num, unsigned short Value ); static void qt_close(struct usb_serial_port *port, struct file *filp);
static int BoxGetRegister(struct usb_serial *serial, unsigned short Uart_Number,
unsigned short Register_Num, __u8 * pValue);
static int BoxSetRegister(struct usb_serial *serial, unsigned short Uart_Number,
unsigned short Register_Num, unsigned short Value);
static void qt_write_bulk_callback(struct urb *urb); static void qt_write_bulk_callback(struct urb *urb);
static int qt_write (struct usb_serial_port *port, int from_user, const unsigned char *buf, int count); static int qt_write(struct usb_serial_port *port, int from_user,
const unsigned char *buf, int count);
static void port_softint(struct work_struct *work); static void port_softint(struct work_struct *work);
static int qt_write_room (struct usb_serial_port *port); static int qt_write_room(struct usb_serial_port *port);
static int qt_chars_in_buffer (struct usb_serial_port *port); static int qt_chars_in_buffer(struct usb_serial_port *port);
static int qt_ioctl(struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg); static int qt_ioctl(struct usb_serial_port *port, struct file *file,
static void qt_set_termios(struct usb_serial_port *port, struct ktermios *old_termios); unsigned int cmd, unsigned long arg);
static int BoxSetHW_FlowCtrl(struct usb_serial *serial, unsigned int UartNumber, int bSet); static void qt_set_termios(struct usb_serial_port *port,
struct ktermios *old_termios);
static int BoxSetHW_FlowCtrl(struct usb_serial *serial, unsigned int UartNumber,
int bSet);
static int BoxDisable_SW_FlowCtrl(struct usb_serial *serial, __u16 UartNumber); static int BoxDisable_SW_FlowCtrl(struct usb_serial *serial, __u16 UartNumber);
static int EmulateWriteQMCR_Reg(int index, unsigned uc_value); static int EmulateWriteQMCR_Reg(int index, unsigned uc_value);
static int EmulateReadQMCR_Reg(int index, unsigned *uc_value); static int EmulateReadQMCR_Reg(int index, unsigned *uc_value);
static struct usb_serial *find_the_box(unsigned int index); static struct usb_serial *find_the_box(unsigned int index);
int ioctl_serial_usb (struct inode *innod, struct file *filp, unsigned int cmd, unsigned long arg); int ioctl_serial_usb(struct inode *innod, struct file *filp, unsigned int cmd,
unsigned long arg);
static int BoxSetSW_FlowCtrl(struct usb_serial *serial, __u16 Uart, unsigned char stop_char, unsigned char start_char); static int BoxSetSW_FlowCtrl(struct usb_serial *serial, __u16 Uart,
unsigned char stop_char, unsigned char start_char);
static void qt_read_bulk_callback(struct urb *urb); static void qt_read_bulk_callback(struct urb *urb);
static void port_sofrint(void *private); static void port_sofrint(void *private);
static void return_serial(struct usb_serial *serial); static void return_serial(struct usb_serial *serial);
static int serial_tiocmset(struct tty_struct *tty, struct file *file,
static int serial_tiocmset (struct tty_struct *tty, struct file *file, unsigned int set, unsigned int clear); unsigned int set, unsigned int clear);
static int serial_tiocmget(struct tty_struct *tty, struct file *file); static int serial_tiocmget(struct tty_struct *tty, struct file *file);
static int qt_tiocmset(struct usb_serial_port *port, struct file *file,
unsigned int value);
static int qt_tiocmget(struct usb_serial_port *port, struct file *file);
static int qt_tiocmset(struct usb_serial_port *port, struct file * file, unsigned int value);
static int qt_tiocmget(struct usb_serial_port *port, struct file * file);
/* Version Information */ /* Version Information */
#define DRIVER_VERSION "v2.14" #define DRIVER_VERSION "v2.14"
...@@ -370,35 +368,40 @@ static int qt_tiocmget(struct usb_serial_port *port, struct file * file); ...@@ -370,35 +368,40 @@ static int qt_tiocmget(struct usb_serial_port *port, struct file * file);
#define DEVICE_ID_QUATECH_RS422_16_PORT_C 0xC0B2 //HSU200C #define DEVICE_ID_QUATECH_RS422_16_PORT_C 0xC0B2 //HSU200C
#define DEVICE_ID_QUATECH_RS422_16_PORT_D 0xC0B3 //HSU200D #define DEVICE_ID_QUATECH_RS422_16_PORT_D 0xC0B3 //HSU200D
/* table of Quatech devices */ /* table of Quatech devices */
static struct usb_device_id serqt_table [] = { static struct usb_device_id serqt_table[] = {
{ USB_DEVICE(USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS232_SINGLE_PORT)}, {USB_DEVICE
{ USB_DEVICE(USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS422_SINGLE_PORT)}, (USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS232_SINGLE_PORT)},
{ USB_DEVICE(USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS232_DUAL_PORT)}, {USB_DEVICE
{ USB_DEVICE(USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS422_DUAL_PORT)}, (USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS422_SINGLE_PORT)},
{ USB_DEVICE(USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS232_FOUR_PORT)}, {USB_DEVICE(USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS232_DUAL_PORT)},
{ USB_DEVICE(USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS422_FOUR_PORT)}, {USB_DEVICE(USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS422_DUAL_PORT)},
{ USB_DEVICE(USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS232_EIGHT_PORT_A)}, {USB_DEVICE(USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS232_FOUR_PORT)},
{ USB_DEVICE(USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS232_EIGHT_PORT_B)}, {USB_DEVICE(USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS422_FOUR_PORT)},
{ USB_DEVICE(USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS422_EIGHT_PORT_A)}, {USB_DEVICE
{ USB_DEVICE(USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS422_EIGHT_PORT_B)}, (USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS232_EIGHT_PORT_A)},
{ USB_DEVICE(USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS232_16_PORT_A)}, {USB_DEVICE
{ USB_DEVICE(USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS232_16_PORT_B)}, (USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS232_EIGHT_PORT_B)},
{ USB_DEVICE(USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS232_16_PORT_C)}, {USB_DEVICE
{ USB_DEVICE(USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS232_16_PORT_D)}, (USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS422_EIGHT_PORT_A)},
{ USB_DEVICE(USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS422_16_PORT_A)}, {USB_DEVICE
{ USB_DEVICE(USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS422_16_PORT_B)}, (USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS422_EIGHT_PORT_B)},
{ USB_DEVICE(USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS422_16_PORT_C)}, {USB_DEVICE(USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS232_16_PORT_A)},
{ USB_DEVICE(USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS422_16_PORT_D)}, {USB_DEVICE(USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS232_16_PORT_B)},
{USB_DEVICE(USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS232_16_PORT_C)},
{USB_DEVICE(USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS232_16_PORT_D)},
{USB_DEVICE(USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS422_16_PORT_A)},
{USB_DEVICE(USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS422_16_PORT_B)},
{USB_DEVICE(USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS422_16_PORT_C)},
{USB_DEVICE(USB_VENDOR_ID_QUATECH, DEVICE_ID_QUATECH_RS422_16_PORT_D)},
{} /* Terminating entry */ {} /* Terminating entry */
}; };
MODULE_DEVICE_TABLE(usb, serqt_table); MODULE_DEVICE_TABLE(usb, serqt_table);
static int major_number; static int major_number;
static struct usb_serial *serial_table[SERIAL_TTY_MINORS]; /* initially all NULL */ static struct usb_serial *serial_table[SERIAL_TTY_MINORS]; /* initially all NULL */
/* table of Quatech 422devices */ /* table of Quatech 422devices */
static unsigned int serqt_422_table[] = { static unsigned int serqt_422_table[] = {
DEVICE_ID_QUATECH_RS422_SINGLE_PORT, DEVICE_ID_QUATECH_RS422_SINGLE_PORT,
...@@ -413,8 +416,6 @@ static unsigned int serqt_422_table[] = { ...@@ -413,8 +416,6 @@ static unsigned int serqt_422_table[] = {
0 /* terminate with zero */ 0 /* terminate with zero */
}; };
/* usb specific object needed to register this driver with the usb subsystem */ /* usb specific object needed to register this driver with the usb subsystem */
static struct usb_driver serqt_usb_driver = { static struct usb_driver serqt_usb_driver = {
.name = "quatech-usb-serial", .name = "quatech-usb-serial",
...@@ -460,7 +461,8 @@ static struct tty_driver serial_tty_driver = { ...@@ -460,7 +461,8 @@ static struct tty_driver serial_tty_driver = {
.init_termios.c_iflag = ICRNL | IXON, .init_termios.c_iflag = ICRNL | IXON,
.init_termios.c_oflag = OPOST, .init_termios.c_oflag = OPOST,
.init_termios.c_lflag= ISIG | ICANON | ECHO | ECHOE | ECHOK | ECHOCTL | ECHOKE | IEXTEN, .init_termios.c_lflag =
ISIG | ICANON | ECHO | ECHOE | ECHOK | ECHOCTL | ECHOKE | IEXTEN,
}; };
//fops for parent device //fops for parent device
...@@ -469,7 +471,6 @@ static struct file_operations serialqt_usb_fops = { ...@@ -469,7 +471,6 @@ static struct file_operations serialqt_usb_fops = {
}; };
/** /**
* serqt_probe * serqt_probe
* *
...@@ -503,13 +504,11 @@ static int serqt_probe(struct usb_interface *interface, ...@@ -503,13 +504,11 @@ static int serqt_probe(struct usb_interface *interface,
/* let's find the endpoints needed */ /* let's find the endpoints needed */
/* check out the endpoints */ /* check out the endpoints */
iface_desc = interface->cur_altsetting;; iface_desc = interface->cur_altsetting;;
for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
{
endpoint = &iface_desc->endpoint[i].desc; endpoint = &iface_desc->endpoint[i].desc;
if ((endpoint->bEndpointAddress & 0x80) && if ((endpoint->bEndpointAddress & 0x80) &&
((endpoint->bmAttributes & 3) == 0x02)) ((endpoint->bmAttributes & 3) == 0x02)) {
{
/* we found a bulk in endpoint */ /* we found a bulk in endpoint */
mydbg("found bulk in"); mydbg("found bulk in");
bulk_in_endpoint[num_bulk_in] = endpoint; bulk_in_endpoint[num_bulk_in] = endpoint;
...@@ -517,8 +516,7 @@ static int serqt_probe(struct usb_interface *interface, ...@@ -517,8 +516,7 @@ static int serqt_probe(struct usb_interface *interface,
} }
if (((endpoint->bEndpointAddress & 0x80) == 0x00) && if (((endpoint->bEndpointAddress & 0x80) == 0x00) &&
((endpoint->bmAttributes & 3) == 0x02)) ((endpoint->bmAttributes & 3) == 0x02)) {
{
/* we found a bulk out endpoint */ /* we found a bulk out endpoint */
mydbg("found bulk out\n"); mydbg("found bulk out\n");
bulk_out_endpoint[num_bulk_out] = endpoint; bulk_out_endpoint[num_bulk_out] = endpoint;
...@@ -526,8 +524,7 @@ static int serqt_probe(struct usb_interface *interface, ...@@ -526,8 +524,7 @@ static int serqt_probe(struct usb_interface *interface,
} }
if ((endpoint->bEndpointAddress & 0x80) && if ((endpoint->bEndpointAddress & 0x80) &&
((endpoint->bmAttributes & 3) == 0x03)) ((endpoint->bmAttributes & 3) == 0x03)) {
{
/* we found a interrupt in endpoint */ /* we found a interrupt in endpoint */
mydbg("found interrupt in\n"); mydbg("found interrupt in\n");
interrupt_in_endpoint[num_interrupt_in] = endpoint; interrupt_in_endpoint[num_interrupt_in] = endpoint;
...@@ -538,16 +535,14 @@ static int serqt_probe(struct usb_interface *interface, ...@@ -538,16 +535,14 @@ static int serqt_probe(struct usb_interface *interface,
/* found all that we need */ /* found all that we need */
dev_info(&interface->dev, "Quatech converter detected\n"); dev_info(&interface->dev, "Quatech converter detected\n");
num_ports = num_bulk_out; num_ports = num_bulk_out;
if (num_ports == 0) if (num_ports == 0) {
{
err("Quatech device with no bulk out, not allowed."); err("Quatech device with no bulk out, not allowed.");
return -ENODEV; return -ENODEV;
} }
serial = get_free_serial (num_ports, &minor); serial = get_free_serial(num_ports, &minor);
if (serial == NULL) if (serial == NULL) {
{
err("No more free serial devices"); err("No more free serial devices");
return -ENODEV; return -ENODEV;
} }
...@@ -562,105 +557,89 @@ static int serqt_probe(struct usb_interface *interface, ...@@ -562,105 +557,89 @@ static int serqt_probe(struct usb_interface *interface,
serial->vendor = dev->descriptor.idVendor; serial->vendor = dev->descriptor.idVendor;
serial->product = dev->descriptor.idProduct; serial->product = dev->descriptor.idProduct;
/* set up the endpoint information */ /* set up the endpoint information */
for (i = 0; i < num_bulk_in; ++i) for (i = 0; i < num_bulk_in; ++i) {
{
endpoint = bulk_in_endpoint[i]; endpoint = bulk_in_endpoint[i];
port = &serial->port[i]; port = &serial->port[i];
port->read_urb = usb_alloc_urb (0, GFP_KERNEL); port->read_urb = usb_alloc_urb(0, GFP_KERNEL);
if (!port->read_urb) if (!port->read_urb) {
{
err("No free urbs available"); err("No free urbs available");
goto probe_error; goto probe_error;
} }
buffer_size = endpoint->wMaxPacketSize; buffer_size = endpoint->wMaxPacketSize;
port->bulk_in_endpointAddress = endpoint->bEndpointAddress; port->bulk_in_endpointAddress = endpoint->bEndpointAddress;
port->bulk_in_buffer = kmalloc (buffer_size, GFP_KERNEL); port->bulk_in_buffer = kmalloc(buffer_size, GFP_KERNEL);
port->xfer_to_tty_buffer = kmalloc (buffer_size, GFP_KERNEL); port->xfer_to_tty_buffer = kmalloc(buffer_size, GFP_KERNEL);
if (!port->bulk_in_buffer) if (!port->bulk_in_buffer) {
{
err("Couldn't allocate bulk_in_buffer"); err("Couldn't allocate bulk_in_buffer");
goto probe_error; goto probe_error;
} }
usb_fill_bulk_urb (port->read_urb, dev, usb_fill_bulk_urb(port->read_urb, dev,
usb_rcvbulkpipe (dev, usb_rcvbulkpipe(dev,
endpoint->bEndpointAddress), endpoint->bEndpointAddress),
port->bulk_in_buffer, buffer_size, port->bulk_in_buffer, buffer_size,
qt_read_bulk_callback, qt_read_bulk_callback, port);
port);
} }
for (i = 0; i < num_bulk_out; ++i) for (i = 0; i < num_bulk_out; ++i) {
{
endpoint = bulk_out_endpoint[i]; endpoint = bulk_out_endpoint[i];
port = &serial->port[i]; port = &serial->port[i];
port->write_urb = usb_alloc_urb (0, GFP_KERNEL); port->write_urb = usb_alloc_urb(0, GFP_KERNEL);
if (!port->write_urb) if (!port->write_urb) {
{
err("No free urbs available"); err("No free urbs available");
goto probe_error; goto probe_error;
} }
buffer_size = endpoint->wMaxPacketSize; buffer_size = endpoint->wMaxPacketSize;
port->bulk_out_size = buffer_size; port->bulk_out_size = buffer_size;
port->bulk_out_endpointAddress = endpoint->bEndpointAddress; port->bulk_out_endpointAddress = endpoint->bEndpointAddress;
port->bulk_out_buffer = kmalloc (buffer_size, GFP_KERNEL); port->bulk_out_buffer = kmalloc(buffer_size, GFP_KERNEL);
if (!port->bulk_out_buffer) if (!port->bulk_out_buffer) {
{
err("Couldn't allocate bulk_out_buffer"); err("Couldn't allocate bulk_out_buffer");
goto probe_error; goto probe_error;
} }
usb_fill_bulk_urb (port->write_urb, dev, usb_fill_bulk_urb(port->write_urb, dev,
usb_sndbulkpipe (dev, usb_sndbulkpipe(dev,
endpoint->bEndpointAddress), endpoint->bEndpointAddress),
port->bulk_out_buffer, buffer_size, port->bulk_out_buffer, buffer_size,
qt_write_bulk_callback, qt_write_bulk_callback, port);
port);
} }
//For us numb of bulkin or out = number of ports //For us numb of bulkin or out = number of ports
mydbg("%s - setting up %d port structures for this device\n", __FUNCTION__, num_bulk_in); mydbg("%s - setting up %d port structures for this device\n",
for (i = 0; i < num_bulk_in; ++i) __FUNCTION__, num_bulk_in);
{ for (i = 0; i < num_bulk_in; ++i) {
port = &serial->port[i]; port = &serial->port[i];
port->number = i + serial->minor; port->number = i + serial->minor;
port->serial = serial; port->serial = serial;
INIT_WORK(&port->work, port_softint); INIT_WORK(&port->work, port_softint);
init_MUTEX (&port->sem); init_MUTEX(&port->sem);
} }
status = box_get_device(serial, &DeviceData); status = box_get_device(serial, &DeviceData);
if (status < 0) if (status < 0) {
{ mydbg(__FILE__ "box_get_device failed");
mydbg(__FILE__"box_get_device failed");
goto probe_error; goto probe_error;
} }
mydbg(__FILE__"DeviceData.portb = 0x%x",DeviceData.portb); mydbg(__FILE__ "DeviceData.portb = 0x%x", DeviceData.portb);
DeviceData.portb &= ~FULLPWRBIT; DeviceData.portb &= ~FULLPWRBIT;
mydbg(__FILE__"Changing DeviceData.portb to 0x%x",DeviceData.portb); mydbg(__FILE__ "Changing DeviceData.portb to 0x%x", DeviceData.portb);
status = box_set_device(serial, &DeviceData); status = box_set_device(serial, &DeviceData);
if (status < 0) if (status < 0) {
{ mydbg(__FILE__ "box_set_device failed\n");
mydbg(__FILE__"box_set_device failed\n");
goto probe_error; goto probe_error;
} }
/* initialize the devfs nodes for this device and let the user know what ports we are bound to */ /* initialize the devfs nodes for this device and let the user know what ports we are bound to */
for (i = 0; i < serial->num_ports; ++i) for (i = 0; i < serial->num_ports; ++i) {
{ dev_info(&interface->dev,
dev_info(&interface->dev, "Converter now attached to ttyUSB%d (or usb/tts/%d for devfs)", "Converter now attached to ttyUSB%d (or usb/tts/%d for devfs)",
serial->port[i].number, serial->port[i].number); serial->port[i].number, serial->port[i].number);
} }
...@@ -668,16 +647,13 @@ static int serqt_probe(struct usb_interface *interface, ...@@ -668,16 +647,13 @@ static int serqt_probe(struct usb_interface *interface,
///***********TAG add start next board here ****/// ///***********TAG add start next board here ****///
status = box_get_device(serial, &DeviceData); status = box_get_device(serial, &DeviceData);
if (status < 0) if (status < 0) {
{ mydbg(__FILE__ "box_get_device failed");
mydbg(__FILE__"box_get_device failed");
goto probe_error; goto probe_error;
} }
//*****************and before we power up lets initialiaze parnent device stuff here before //*****************and before we power up lets initialiaze parnent device stuff here before
//*****************we set thmem via any other method such as the property pages //*****************we set thmem via any other method such as the property pages
switch (serial->product) switch (serial->product) {
{
case DEVICE_ID_QUATECH_RS232_SINGLE_PORT: case DEVICE_ID_QUATECH_RS232_SINGLE_PORT:
case DEVICE_ID_QUATECH_RS232_DUAL_PORT: case DEVICE_ID_QUATECH_RS232_DUAL_PORT:
case DEVICE_ID_QUATECH_RS232_FOUR_PORT: case DEVICE_ID_QUATECH_RS232_FOUR_PORT:
...@@ -693,7 +669,6 @@ static int serqt_probe(struct usb_interface *interface, ...@@ -693,7 +669,6 @@ static int serqt_probe(struct usb_interface *interface,
DeviceData.portb |= RS232_MODE; DeviceData.portb |= RS232_MODE;
break; break;
case DEVICE_ID_QUATECH_RS422_SINGLE_PORT: case DEVICE_ID_QUATECH_RS422_SINGLE_PORT:
case DEVICE_ID_QUATECH_RS422_DUAL_PORT: case DEVICE_ID_QUATECH_RS422_DUAL_PORT:
case DEVICE_ID_QUATECH_RS422_FOUR_PORT: case DEVICE_ID_QUATECH_RS422_FOUR_PORT:
...@@ -717,84 +692,69 @@ static int serqt_probe(struct usb_interface *interface, ...@@ -717,84 +692,69 @@ static int serqt_probe(struct usb_interface *interface,
} }
status = BoxSetPrebufferLevel(serial); //sets to default vaue status = BoxSetPrebufferLevel(serial); //sets to default vaue
if (status < 0) if (status < 0) {
{ mydbg(__FILE__ "BoxSetPrebufferLevel failed\n");
mydbg(__FILE__"BoxSetPrebufferLevel failed\n");
goto probe_error; goto probe_error;
} }
status = BoxSetATC(serial, ATC_DISABLED); status = BoxSetATC(serial, ATC_DISABLED);
if (status < 0) if (status < 0) {
{ mydbg(__FILE__ "BoxSetATC failed\n");
mydbg(__FILE__"BoxSetATC failed\n");
goto probe_error; goto probe_error;
} }
//**************************************************************************** //****************************************************************************
mydbg(__FILE__"DeviceData.portb = 0x%x",DeviceData.portb); mydbg(__FILE__ "DeviceData.portb = 0x%x", DeviceData.portb);
DeviceData.portb |= NEXT_BOARD_POWER_BIT; DeviceData.portb |= NEXT_BOARD_POWER_BIT;
mydbg(__FILE__"Changing DeviceData.portb to 0x%x",DeviceData.portb); mydbg(__FILE__ "Changing DeviceData.portb to 0x%x", DeviceData.portb);
status = box_set_device(serial, &DeviceData); status = box_set_device(serial, &DeviceData);
if (status < 0) if (status < 0) {
{ mydbg(__FILE__ "box_set_device failed\n");
mydbg(__FILE__"box_set_device failed\n");
goto probe_error; goto probe_error;
} }
mydbg("Exit Success %s\n", __FUNCTION__); mydbg("Exit Success %s\n", __FUNCTION__);
usb_set_intfdata (interface, serial); usb_set_intfdata(interface, serial);
return 0; return 0;
probe_error:
for (i = 0; i < num_bulk_in; ++i) {
probe_error:
for (i = 0; i < num_bulk_in; ++i)
{
port = &serial->port[i]; port = &serial->port[i];
if (port->read_urb) if (port->read_urb)
usb_free_urb (port->read_urb); usb_free_urb(port->read_urb);
if (port->bulk_in_buffer) if (port->bulk_in_buffer)
kfree (port->bulk_in_buffer); kfree(port->bulk_in_buffer);
} }
for (i = 0; i < num_bulk_out; ++i) for (i = 0; i < num_bulk_out; ++i) {
{
port = &serial->port[i]; port = &serial->port[i];
if (port->write_urb) if (port->write_urb)
usb_free_urb (port->write_urb); usb_free_urb(port->write_urb);
if (port->bulk_out_buffer) if (port->bulk_out_buffer)
kfree (port->bulk_out_buffer); kfree(port->bulk_out_buffer);
if (port->xfer_to_tty_buffer) if (port->xfer_to_tty_buffer)
kfree (port->xfer_to_tty_buffer); kfree(port->xfer_to_tty_buffer);
} }
for (i = 0; i < num_interrupt_in; ++i) for (i = 0; i < num_interrupt_in; ++i) {
{
port = &serial->port[i]; port = &serial->port[i];
if (port->interrupt_in_urb) if (port->interrupt_in_urb)
usb_free_urb (port->interrupt_in_urb); usb_free_urb(port->interrupt_in_urb);
if (port->interrupt_in_buffer) if (port->interrupt_in_buffer)
kfree (port->interrupt_in_buffer); kfree(port->interrupt_in_buffer);
} }
/* return the minor range that this device had */ /* return the minor range that this device had */
return_serial (serial); return_serial(serial);
mydbg("Exit fail %s\n", __FUNCTION__); mydbg("Exit fail %s\n", __FUNCTION__);
/* free up any memory that we allocated */ /* free up any memory that we allocated */
kfree (serial); kfree(serial);
return -EIO; return -EIO;
} }
//returns the serial_table array pointers that are taken //returns the serial_table array pointers that are taken
//up in consecutive positions for each port to a common usb_serial structure //up in consecutive positions for each port to a common usb_serial structure
//back to NULL //back to NULL
...@@ -807,8 +767,7 @@ static void return_serial(struct usb_serial *serial) ...@@ -807,8 +767,7 @@ static void return_serial(struct usb_serial *serial)
if (serial == NULL) if (serial == NULL)
return; return;
for (i = 0; i < serial->num_ports; ++i) for (i = 0; i < serial->num_ports; ++i) {
{
serial_table[serial->minor + i] = NULL; serial_table[serial->minor + i] = NULL;
} }
...@@ -820,7 +779,7 @@ static void return_serial(struct usb_serial *serial) ...@@ -820,7 +779,7 @@ static void return_serial(struct usb_serial *serial)
//,allocates a stucture points to it in all the structures, and returns the index //,allocates a stucture points to it in all the structures, and returns the index
//to the first location in the array in the "minor" variable. //to the first location in the array in the "minor" variable.
static struct usb_serial *get_free_serial (int num_ports, int *minor) static struct usb_serial *get_free_serial(int num_ports, int *minor)
{ {
struct usb_serial *serial = NULL; struct usb_serial *serial = NULL;
int i, j; int i, j;
...@@ -829,8 +788,7 @@ static struct usb_serial *get_free_serial (int num_ports, int *minor) ...@@ -829,8 +788,7 @@ static struct usb_serial *get_free_serial (int num_ports, int *minor)
mydbg("%s %d\n", __FUNCTION__, num_ports); mydbg("%s %d\n", __FUNCTION__, num_ports);
*minor = 0; *minor = 0;
for (i = 0; i < SERIAL_TTY_MINORS; ++i) for (i = 0; i < SERIAL_TTY_MINORS; ++i) {
{
if (serial_table[i]) if (serial_table[i])
continue; continue;
...@@ -838,14 +796,13 @@ static struct usb_serial *get_free_serial (int num_ports, int *minor) ...@@ -838,14 +796,13 @@ static struct usb_serial *get_free_serial (int num_ports, int *minor)
//find a spot in the array where you can fit consecutive positions //find a spot in the array where you can fit consecutive positions
//to put the pointers to the usb_serail allocated structure for all //to put the pointers to the usb_serail allocated structure for all
//the minor numbers (ie. ports) //the minor numbers (ie. ports)
for (j = 1; j <= num_ports-1; ++j) for (j = 1; j <= num_ports - 1; ++j)
if (serial_table[i+j]) if (serial_table[i + j])
good_spot = 0; good_spot = 0;
if (good_spot == 0) if (good_spot == 0)
continue; continue;
if (!(serial = kmalloc(sizeof(struct usb_serial), GFP_KERNEL))) if (!(serial = kmalloc(sizeof(struct usb_serial), GFP_KERNEL))) {
{
err("%s - Out of memory", __FUNCTION__); err("%s - Out of memory", __FUNCTION__);
return NULL; return NULL;
} }
...@@ -855,14 +812,16 @@ static struct usb_serial *get_free_serial (int num_ports, int *minor) ...@@ -855,14 +812,16 @@ static struct usb_serial *get_free_serial (int num_ports, int *minor)
mydbg("%s - minor base = %d\n", __FUNCTION__, *minor); mydbg("%s - minor base = %d\n", __FUNCTION__, *minor);
//copy in the pointer into the array starting a the *minor position //copy in the pointer into the array starting a the *minor position
//*minor is the index into the array //*minor is the index into the array
for (i = *minor+1; (i < (*minor + num_ports)) && (i < SERIAL_TTY_MINORS); ++i) for (i = *minor + 1;
(i < (*minor + num_ports)) && (i < SERIAL_TTY_MINORS); ++i)
serial_table[i] = serial; serial_table[i] = serial;
return serial; return serial;
} }
return NULL; return NULL;
} }
static int flip_that( struct tty_struct *tty, __u16 UartNumber, struct usb_serial *serial) static int flip_that(struct tty_struct *tty, __u16 UartNumber,
struct usb_serial *serial)
{ {
tty_flip_buffer_push(tty); tty_flip_buffer_push(tty);
tty_schedule_flip(tty); tty_schedule_flip(tty);
...@@ -873,7 +832,7 @@ static int flip_that( struct tty_struct *tty, __u16 UartNumber, struct usb_ser ...@@ -873,7 +832,7 @@ static int flip_that( struct tty_struct *tty, __u16 UartNumber, struct usb_ser
static void port_sofrint(void *private) static void port_sofrint(void *private)
{ {
struct usb_serial_port *port = (struct usb_serial_port *)private; struct usb_serial_port *port = (struct usb_serial_port *)private;
struct usb_serial *serial = get_usb_serial (port, __FUNCTION__); struct usb_serial *serial = get_usb_serial(port, __FUNCTION__);
struct tty_struct *tty = port->tty; struct tty_struct *tty = port->tty;
unsigned char *data = port->read_urb->transfer_buffer; unsigned char *data = port->read_urb->transfer_buffer;
unsigned int UartNumber; unsigned int UartNumber;
...@@ -886,9 +845,9 @@ static void port_sofrint(void *private) ...@@ -886,9 +845,9 @@ static void port_sofrint(void *private)
UartNumber = tty->index - serial->minor; UartNumber = tty->index - serial->minor;
mydbg("%s - port %d\n", __FUNCTION__, port->number); mydbg("%s - port %d\n", __FUNCTION__, port->number);
mydbg ("%s - port->RxHolding = %d\n", __FUNCTION__, port->RxHolding); mydbg("%s - port->RxHolding = %d\n", __FUNCTION__, port->RxHolding);
if (port_paranoia_check (port, __FUNCTION__) != 0) { if (port_paranoia_check(port, __FUNCTION__) != 0) {
mydbg("%s - port_paranoia_check, exiting\n", __FUNCTION__); mydbg("%s - port_paranoia_check, exiting\n", __FUNCTION__);
port->ReadBulkStopped = 1; port->ReadBulkStopped = 1;
return; return;
...@@ -904,7 +863,6 @@ static void port_sofrint(void *private) ...@@ -904,7 +863,6 @@ static void port_sofrint(void *private)
port->ReadBulkStopped = 1; port->ReadBulkStopped = 1;
return; return;
} }
//RxHolding is asserted by throttle, if we assert it, we're not receiving any more //RxHolding is asserted by throttle, if we assert it, we're not receiving any more
//characters and let the box handle the flow control //characters and let the box handle the flow control
if (port->RxHolding == 1) { if (port->RxHolding == 1) {
...@@ -915,27 +873,28 @@ static void port_sofrint(void *private) ...@@ -915,27 +873,28 @@ static void port_sofrint(void *private)
if (urb->status) { if (urb->status) {
port->ReadBulkStopped = 1; port->ReadBulkStopped = 1;
mydbg("%s - nonzero read bulk status received: %d\n", __FUNCTION__, urb->status); mydbg("%s - nonzero read bulk status received: %d\n",
__FUNCTION__, urb->status);
return; return;
} }
tty = port->tty; tty = port->tty;
mydbg("%s - port %d, tty =0x%p\n", __FUNCTION__, port->number, tty); mydbg("%s - port %d, tty =0x%p\n", __FUNCTION__, port->number, tty);
if (tty && RxCount) { if (tty && RxCount) {
flag_data = 0; flag_data = 0;
for (i = 0; i < RxCount ; ++i) { for (i = 0; i < RxCount; ++i) {
//Look ahead code here //Look ahead code here
if ((i <= (RxCount - 3)) && (THISCHAR == 0x1b) && (NEXTCHAR == 0x1b)) { if ((i <= (RxCount - 3)) && (THISCHAR == 0x1b)
&& (NEXTCHAR == 0x1b)) {
flag = 0; flag = 0;
switch (THIRDCHAR) { switch (THIRDCHAR) {
case 0x00: case 0x00:
//Line status change 4th byte must follow //Line status change 4th byte must follow
if (i > (RxCount - 4)) { if (i > (RxCount - 4)) {
mydbg("Illegal escape sequences in received data\n"); mydbg
("Illegal escape sequences in received data\n");
break; break;
} }
ProcessLineStatus(port, FOURTHCHAR); ProcessLineStatus(port, FOURTHCHAR);
...@@ -948,7 +907,8 @@ static void port_sofrint(void *private) ...@@ -948,7 +907,8 @@ static void port_sofrint(void *private)
mydbg("Modem status status. \n"); mydbg("Modem status status. \n");
if (i > (RxCount - 4)) { if (i > (RxCount - 4)) {
mydbg("Illegal escape sequences in received data\n"); mydbg
("Illegal escape sequences in received data\n");
break; break;
} }
ProcessModemStatus(port, FOURTHCHAR); ProcessModemStatus(port, FOURTHCHAR);
...@@ -963,176 +923,151 @@ static void port_sofrint(void *private) ...@@ -963,176 +923,151 @@ static void port_sofrint(void *private)
i += 2; i += 2;
break; break;
}//end switch } //end switch
if (flag == 1) if (flag == 1)
continue; continue;
} //endif } //endif
if(tty && urb->actual_length) { if (tty && urb->actual_length) {
tty_buffer_request_room(tty, 1); tty_buffer_request_room(tty, 1);
tty_insert_flip_string(tty, (data + i), 1); tty_insert_flip_string(tty, (data + i), 1);
} }
} //endfor
}//endfor
tty_flip_buffer_push(tty); tty_flip_buffer_push(tty);
}//endif } //endif
/* Continue trying to always read */ /* Continue trying to always read */
usb_fill_bulk_urb (port->read_urb, serial->dev, usb_fill_bulk_urb(port->read_urb, serial->dev,
usb_rcvbulkpipe (serial->dev, usb_rcvbulkpipe(serial->dev,
port->bulk_in_endpointAddress), port->bulk_in_endpointAddress),
port->read_urb->transfer_buffer, port->read_urb->transfer_buffer,
port->read_urb->transfer_buffer_length, port->read_urb->transfer_buffer_length,
qt_read_bulk_callback, port); qt_read_bulk_callback, port);
result = usb_submit_urb(port->read_urb, GFP_ATOMIC); result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
if (result) if (result)
mydbg("%s - failed resubmitting read urb, error %d", __FUNCTION__, result); mydbg("%s - failed resubmitting read urb, error %d",
else __FUNCTION__, result);
{ else {
if (tty && RxCount) if (tty && RxCount)
flip_that(tty, UartNumber, serial); flip_that(tty, UartNumber, serial);
} }
return; return;
} }
static void qt_read_bulk_callback(struct urb *urb) static void qt_read_bulk_callback(struct urb *urb)
{ {
struct usb_serial_port *port = (struct usb_serial_port *)urb->context; struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
if (urb->status) {
if (urb->status)
{
port->ReadBulkStopped = 1; port->ReadBulkStopped = 1;
mydbg("%s - nonzero write bulk status received: %d\n", __FUNCTION__, urb->status); mydbg("%s - nonzero write bulk status received: %d\n",
__FUNCTION__, urb->status);
return; return;
} }
port_sofrint((void *) port); port_sofrint((void *)port);
schedule_work(&port->work); schedule_work(&port->work);
} }
static void ProcessRxChar(struct usb_serial_port *port, unsigned char Data)
static void ProcessRxChar(struct usb_serial_port *port, unsigned char Data){ {
struct tty_struct *tty; struct tty_struct *tty;
struct urb *urb = port->read_urb; struct urb *urb = port->read_urb;
tty = port->tty; tty = port->tty;
/* if we insert more than TTY_FLIPBUF_SIZE characters, we drop them. */ /* if we insert more than TTY_FLIPBUF_SIZE characters, we drop them. */
if(tty && urb->actual_length) if (tty && urb->actual_length) {
{
tty_buffer_request_room(tty, 1); tty_buffer_request_room(tty, 1);
tty_insert_flip_string(tty, &Data, 1); tty_insert_flip_string(tty, &Data, 1);
//tty_flip_buffer_push(tty); //tty_flip_buffer_push(tty);
} }
return; return;
} }
static void ProcessLineStatus(struct usb_serial_port *port, unsigned char line_status){ static void ProcessLineStatus(struct usb_serial_port *port,
unsigned char line_status)
{
port->shadowLSR = line_status & (SERIAL_LSR_OE | SERIAL_LSR_PE | SERIAL_LSR_FE | port->shadowLSR =
line_status & (SERIAL_LSR_OE | SERIAL_LSR_PE | SERIAL_LSR_FE |
SERIAL_LSR_BI); SERIAL_LSR_BI);
return; return;
} }
static void ProcessModemStatus(struct usb_serial_port *port,
static void ProcessModemStatus(struct usb_serial_port *port, unsigned char modem_status){ unsigned char modem_status)
{
port->shadowMSR = modem_status; port->shadowMSR = modem_status;
wake_up_interruptible(&port->wait); wake_up_interruptible(&port->wait);
return; return;
} }
static void serqt_usb_disconnect(struct usb_interface *interface)
{
struct usb_serial *serial = usb_get_intfdata(interface);
static void serqt_usb_disconnect(struct usb_interface *interface){
struct usb_serial *serial = usb_get_intfdata (interface);
//struct device *dev = &interface->dev; //struct device *dev = &interface->dev;
struct usb_serial_port *port; struct usb_serial_port *port;
int i; int i;
mydbg ("%s\n", __FUNCTION__); mydbg("%s\n", __FUNCTION__);
if (serial) if (serial) {
{
serial->dev = NULL; serial->dev = NULL;
for (i = 0; i < serial->num_ports; ++i) for (i = 0; i < serial->num_ports; ++i)
serial->port[i].open_count = 0; serial->port[i].open_count = 0;
for (i = 0; i < serial->num_bulk_in; ++i) for (i = 0; i < serial->num_bulk_in; ++i) {
{
port = &serial->port[i]; port = &serial->port[i];
if (port->read_urb) if (port->read_urb) {
{ usb_unlink_urb(port->read_urb);
usb_unlink_urb (port->read_urb); usb_free_urb(port->read_urb);
usb_free_urb (port->read_urb);
} }
if (port->bulk_in_buffer) if (port->bulk_in_buffer)
kfree (port->bulk_in_buffer); kfree(port->bulk_in_buffer);
} }
for (i = 0; i < serial->num_bulk_out; ++i) for (i = 0; i < serial->num_bulk_out; ++i) {
{
port = &serial->port[i]; port = &serial->port[i];
if (port->write_urb) if (port->write_urb) {
{ usb_unlink_urb(port->write_urb);
usb_unlink_urb (port->write_urb); usb_free_urb(port->write_urb);
usb_free_urb (port->write_urb);
} }
if (port->bulk_out_buffer) if (port->bulk_out_buffer)
kfree (port->bulk_out_buffer); kfree(port->bulk_out_buffer);
} }
for (i = 0; i < serial->num_interrupt_in; ++i) for (i = 0; i < serial->num_interrupt_in; ++i) {
{
port = &serial->port[i]; port = &serial->port[i];
if (port->interrupt_in_urb) if (port->interrupt_in_urb) {
{ usb_unlink_urb(port->interrupt_in_urb);
usb_unlink_urb (port->interrupt_in_urb); usb_free_urb(port->interrupt_in_urb);
usb_free_urb (port->interrupt_in_urb);
} }
if (port->interrupt_in_buffer) if (port->interrupt_in_buffer)
kfree (port->interrupt_in_buffer); kfree(port->interrupt_in_buffer);
} }
/* return the minor range that this device had */ /* return the minor range that this device had */
return_serial (serial); return_serial(serial);
/* free up any memory that we allocated */ /* free up any memory that we allocated */
kfree (serial); kfree(serial);
} else {
} else
{
dev_info(&interface->dev, "device disconnected"); dev_info(&interface->dev, "device disconnected");
} }
} }
static struct usb_serial *get_serial_by_minor(unsigned int minor)
static struct usb_serial *get_serial_by_minor (unsigned int minor)
{ {
return serial_table[minor]; return serial_table[minor];
} }
...@@ -1140,7 +1075,8 @@ static struct usb_serial *get_serial_by_minor (unsigned int minor) ...@@ -1140,7 +1075,8 @@ static struct usb_serial *get_serial_by_minor (unsigned int minor)
/***************************************************************************** /*****************************************************************************
* Driver tty interface functions * Driver tty interface functions
*****************************************************************************/ *****************************************************************************/
static int serial_open (struct tty_struct *tty, struct file * filp){ static int serial_open(struct tty_struct *tty, struct file *filp)
{
struct usb_serial *serial; struct usb_serial *serial;
struct usb_serial_port *port; struct usb_serial_port *port;
unsigned int portNumber; unsigned int portNumber;
...@@ -1157,23 +1093,19 @@ static int serial_open (struct tty_struct *tty, struct file * filp){ ...@@ -1157,23 +1093,19 @@ static int serial_open (struct tty_struct *tty, struct file * filp){
/* get the serial object associated with this tty pointer */ /* get the serial object associated with this tty pointer */
serial = get_serial_by_minor(tty->index); serial = get_serial_by_minor(tty->index);
if (serial_paranoia_check(serial, __FUNCTION__))
if (serial_paranoia_check (serial, __FUNCTION__))
return -ENODEV; return -ENODEV;
/* set up our port structure making the tty driver remember our port object, and us it */ /* set up our port structure making the tty driver remember our port object, and us it */
portNumber = tty->index - serial->minor; portNumber = tty->index - serial->minor;
port = &serial->port[portNumber]; port = &serial->port[portNumber];
tty->driver_data = port; tty->driver_data = port;
down (&port->sem); down(&port->sem);
port->tty = tty; port->tty = tty;
++port->open_count; ++port->open_count;
if (port->open_count == 1) if (port->open_count == 1) {
{
port->closePending = 0; port->closePending = 0;
mydbg("%s port->closepending = 0\n", __FUNCTION__); mydbg("%s port->closepending = 0\n", __FUNCTION__);
...@@ -1183,19 +1115,21 @@ static int serial_open (struct tty_struct *tty, struct file * filp){ ...@@ -1183,19 +1115,21 @@ static int serial_open (struct tty_struct *tty, struct file * filp){
retval = qt_open(port, filp); retval = qt_open(port, filp);
} }
if (retval) if (retval) {
{
port->open_count = 0; port->open_count = 0;
} }
mydbg("%s returning port->closePending = %d\n", __FUNCTION__, port->closePending); mydbg("%s returning port->closePending = %d\n", __FUNCTION__,
port->closePending);
up (&port->sem); up(&port->sem);
return retval; return retval;
} }
/***************************************************************************** /*****************************************************************************
*device's specific driver functions *device's specific driver functions
*****************************************************************************/ *****************************************************************************/
static int qt_open (struct usb_serial_port *port, struct file *filp){ static int qt_open(struct usb_serial_port *port, struct file *filp)
{
struct usb_serial *serial = port->serial; struct usb_serial *serial = port->serial;
int result = 0; int result = 0;
unsigned int UartNumber; unsigned int UartNumber;
...@@ -1205,10 +1139,7 @@ static int qt_open (struct usb_serial_port *port, struct file *filp){ ...@@ -1205,10 +1139,7 @@ static int qt_open (struct usb_serial_port *port, struct file *filp){
unsigned char default_LCR = SERIAL_8_DATA; // 8, none , 1 unsigned char default_LCR = SERIAL_8_DATA; // 8, none , 1
int status = 0; int status = 0;
if (port_paranoia_check(port, __FUNCTION__))
if (port_paranoia_check (port, __FUNCTION__))
return -ENODEV; return -ENODEV;
mydbg("%s - port %d\n", __FUNCTION__, port->number); mydbg("%s - port %d\n", __FUNCTION__, port->number);
...@@ -1219,27 +1150,25 @@ static int qt_open (struct usb_serial_port *port, struct file *filp){ ...@@ -1219,27 +1150,25 @@ static int qt_open (struct usb_serial_port *port, struct file *filp){
if (port->tty) if (port->tty)
port->tty->low_latency = 0; port->tty->low_latency = 0;
UartNumber = port->tty->index - serial->minor; UartNumber = port->tty->index - serial->minor;
status = box_get_device(serial, &DeviceData); status = box_get_device(serial, &DeviceData);
if (status < 0) if (status < 0) {
{ mydbg(__FILE__ "box_get_device failed\n");
mydbg(__FILE__"box_get_device failed\n");
return status; return status;
} }
serial->num_OpenCount++; serial->num_OpenCount++;
mydbg("%s serial->num_OpenCount = %d\n", __FUNCTION__, serial->num_OpenCount); mydbg("%s serial->num_OpenCount = %d\n", __FUNCTION__,
serial->num_OpenCount);
//Open uart channel //Open uart channel
//Port specific setups //Port specific setups
status = BoxOPenCloseChannel(serial, UartNumber, 1, &ChannelData); status = BoxOPenCloseChannel(serial, UartNumber, 1, &ChannelData);
if (status < 0) if (status < 0) {
{ mydbg(__FILE__ "BoxOPenCloseChannel failed\n");
mydbg(__FILE__"BoxOPenCloseChannel failed\n");
return status; return status;
} }
mydbg(__FILE__"BoxOPenCloseChannel completed.\n"); mydbg(__FILE__ "BoxOPenCloseChannel completed.\n");
port->shadowLSR = ChannelData.line_status & port->shadowLSR = ChannelData.line_status &
(SERIAL_LSR_OE | SERIAL_LSR_PE | SERIAL_LSR_FE | SERIAL_LSR_BI); (SERIAL_LSR_OE | SERIAL_LSR_PE | SERIAL_LSR_FE | SERIAL_LSR_BI);
...@@ -1247,42 +1176,38 @@ static int qt_open (struct usb_serial_port *port, struct file *filp){ ...@@ -1247,42 +1176,38 @@ static int qt_open (struct usb_serial_port *port, struct file *filp){
port->shadowMSR = ChannelData.modem_status & port->shadowMSR = ChannelData.modem_status &
(SERIAL_MSR_CTS | SERIAL_MSR_DSR | SERIAL_MSR_RI | SERIAL_MSR_CD); (SERIAL_MSR_CTS | SERIAL_MSR_DSR | SERIAL_MSR_RI | SERIAL_MSR_CD);
//Set Baud rate to default and turn off (default)flow control here //Set Baud rate to default and turn off (default)flow control here
status = BoxSetUart(serial, UartNumber, default_divisor, default_LCR); status = BoxSetUart(serial, UartNumber, default_divisor, default_LCR);
if (status < 0) if (status < 0) {
{ mydbg(__FILE__ "BoxSetUart failed\n");
mydbg(__FILE__"BoxSetUart failed\n");
return status; return status;
} }
mydbg(__FILE__"BoxSetUart completed.\n"); mydbg(__FILE__ "BoxSetUart completed.\n");
//Put this here to make it responsive to stty and defauls set by the tty layer //Put this here to make it responsive to stty and defauls set by the tty layer
qt_set_termios(port, NULL); qt_set_termios(port, NULL);
//Initialize the wait que head //Initialize the wait que head
init_waitqueue_head(&(port->wait)); init_waitqueue_head(&(port->wait));
/* if we have a bulk endpoint, start reading from it */ /* if we have a bulk endpoint, start reading from it */
if (serial->num_bulk_in) if (serial->num_bulk_in) {
{
/* Start reading from the device */ /* Start reading from the device */
usb_fill_bulk_urb (port->read_urb, serial->dev, usb_fill_bulk_urb(port->read_urb, serial->dev,
usb_rcvbulkpipe(serial->dev, port->bulk_in_endpointAddress), usb_rcvbulkpipe(serial->dev,
port->
bulk_in_endpointAddress),
port->read_urb->transfer_buffer, port->read_urb->transfer_buffer,
port->read_urb->transfer_buffer_length, port->read_urb->transfer_buffer_length,
qt_read_bulk_callback, qt_read_bulk_callback, port);
port);
port->ReadBulkStopped = 0; port->ReadBulkStopped = 0;
result = usb_submit_urb(port->read_urb, GFP_ATOMIC); result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
if (result) if (result) {
{ err("%s - failed resubmitting read urb, error %d\n",
err("%s - failed resubmitting read urb, error %d\n", __FUNCTION__, result); __FUNCTION__, result);
port->ReadBulkStopped = 1; port->ReadBulkStopped = 1;
} }
...@@ -1291,34 +1216,32 @@ static int qt_open (struct usb_serial_port *port, struct file *filp){ ...@@ -1291,34 +1216,32 @@ static int qt_open (struct usb_serial_port *port, struct file *filp){
return result; return result;
} }
static void serial_close(struct tty_struct *tty, struct file * filp){ static void serial_close(struct tty_struct *tty, struct file *filp)
struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data; {
struct usb_serial *serial = get_usb_serial (port, __FUNCTION__); struct usb_serial_port *port =
(struct usb_serial_port *)tty->driver_data;
struct usb_serial *serial = get_usb_serial(port, __FUNCTION__);
if (!serial) if (!serial)
return; return;
down (&port->sem); down(&port->sem);
mydbg("%s - port %d\n", __FUNCTION__, port->number); mydbg("%s - port %d\n", __FUNCTION__, port->number);
/* if disconnect beat us to the punch here, there's nothing to do */ /* if disconnect beat us to the punch here, there's nothing to do */
if (tty->driver_data) if (tty->driver_data) {
{ if (!port->open_count) {
if (!port->open_count) mydbg("%s - port not opened\n", __FUNCTION__);
{
mydbg ("%s - port not opened\n", __FUNCTION__);
goto exit; goto exit;
} }
--port->open_count; --port->open_count;
if (port->open_count <= 0) if (port->open_count <= 0) {
{
port->closePending = 1; port->closePending = 1;
mydbg ("%s - port->closePending = 1\n", __FUNCTION__); mydbg("%s - port->closePending = 1\n", __FUNCTION__);
if (serial->dev) if (serial->dev) {
{
qt_close(port, filp); qt_close(port, filp);
port->open_count = 0; port->open_count = 0;
} }
...@@ -1326,15 +1249,15 @@ static void serial_close(struct tty_struct *tty, struct file * filp){ ...@@ -1326,15 +1249,15 @@ static void serial_close(struct tty_struct *tty, struct file * filp){
} }
exit: exit:
up (&port->sem); up(&port->sem);
mydbg("%s - %d return\n", __FUNCTION__, port->number); mydbg("%s - %d return\n", __FUNCTION__, port->number);
} }
static void qt_close (struct usb_serial_port *port, struct file *filp){ static void qt_close(struct usb_serial_port *port, struct file *filp)
{
unsigned long jift = jiffies + 10 * HZ; unsigned long jift = jiffies + 10 * HZ;
__u8 LSR_Value, MCR_Value; __u8 LSR_Value, MCR_Value;
struct usb_serial *serial = port->serial; struct usb_serial *serial = port->serial;
...@@ -1345,80 +1268,75 @@ static void qt_close (struct usb_serial_port *port, struct file *filp){ ...@@ -1345,80 +1268,75 @@ static void qt_close (struct usb_serial_port *port, struct file *filp){
status = 0; status = 0;
LSR_Value = 0; LSR_Value = 0;
mydbg("%s - port %d\n", __FUNCTION__, port->number); mydbg("%s - port %d\n", __FUNCTION__, port->number);
UartNumber = port->tty->index - serial->minor; UartNumber = port->tty->index - serial->minor;
/* shutdown any bulk reads that might be going on */ /* shutdown any bulk reads that might be going on */
if (serial->num_bulk_out) if (serial->num_bulk_out)
usb_unlink_urb (port->write_urb); usb_unlink_urb(port->write_urb);
if (serial->num_bulk_in) if (serial->num_bulk_in)
usb_unlink_urb (port->read_urb); usb_unlink_urb(port->read_urb);
//wait up to 30 seconds for transmitter to empty //wait up to 30 seconds for transmitter to empty
do do {
{ status =
status = BoxGetRegister(serial, UartNumber, LINE_STATUS_REGISTER, &LSR_Value); BoxGetRegister(serial, UartNumber, LINE_STATUS_REGISTER,
if (status < 0) &LSR_Value);
{ if (status < 0) {
mydbg(__FILE__"box_get_device failed\n"); mydbg(__FILE__ "box_get_device failed\n");
break; break;
} }
if ((LSR_Value & SERIAL_LSR_TEMT) && (port->ReadBulkStopped == 1)) if ((LSR_Value & SERIAL_LSR_TEMT)
&& (port->ReadBulkStopped == 1))
break; break;
schedule(); schedule();
} }
while (jiffies <= jift); while (jiffies <= jift);
if(jiffies > jift) if (jiffies > jift)
mydbg("%s - port %d timout of checking transmitter empty\n", __FUNCTION__, port->number); mydbg("%s - port %d timout of checking transmitter empty\n",
__FUNCTION__, port->number);
else else
mydbg("%s - port %d checking transmitter empty succeded\n", __FUNCTION__, port->number); mydbg("%s - port %d checking transmitter empty succeded\n",
__FUNCTION__, port->number);
status =
BoxGetRegister(serial, UartNumber, MODEM_CONTROL_REGISTER,
&MCR_Value);
mydbg(__FILE__ "BoxGetRegister MCR = 0x%x.\n", MCR_Value);
status = BoxGetRegister(serial, UartNumber, MODEM_CONTROL_REGISTER, &MCR_Value); if (status >= 0) {
mydbg(__FILE__"BoxGetRegister MCR = 0x%x.\n", MCR_Value);
if (status >= 0)
{
MCR_Value &= ~(SERIAL_MCR_DTR | SERIAL_MCR_RTS); MCR_Value &= ~(SERIAL_MCR_DTR | SERIAL_MCR_RTS);
// status = BoxSetRegister(serial, UartNumber, MODEM_CONTROL_REGISTER, MCR_Value); // status = BoxSetRegister(serial, UartNumber, MODEM_CONTROL_REGISTER, MCR_Value);
} }
//Close uart channel //Close uart channel
status = BoxOPenCloseChannel(serial, UartNumber, 0, &ChannelData); status = BoxOPenCloseChannel(serial, UartNumber, 0, &ChannelData);
if(status < 0) if (status < 0)
mydbg("%s - port %d BoxOPenCloseChannel failed.\n", __FUNCTION__, port->number); mydbg("%s - port %d BoxOPenCloseChannel failed.\n",
__FUNCTION__, port->number);
serial->num_OpenCount--; serial->num_OpenCount--;
} }
static int serial_write(struct tty_struct *tty, const unsigned char *buf,
int count)
static int serial_write (struct tty_struct * tty, const unsigned char *buf, int count)
{ {
struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data; struct usb_serial_port *port =
(struct usb_serial_port *)tty->driver_data;
struct usb_serial *serial; struct usb_serial *serial;
int retval = -EINVAL; int retval = -EINVAL;
unsigned int UartNumber; unsigned int UartNumber;
int from_user = 0; int from_user = 0;
serial = get_usb_serial(port, __FUNCTION__);
serial = get_usb_serial (port, __FUNCTION__); if (serial == NULL)
if(serial == NULL)
return -ENODEV; return -ENODEV;
//This can happen if we get disconnected a //This can happen if we get disconnected a
if (port->open_count == 0) if (port->open_count == 0) {
{
return -ENODEV; return -ENODEV;
} }
UartNumber = port->tty->index - serial->minor; UartNumber = port->tty->index - serial->minor;
...@@ -1426,78 +1344,69 @@ static int serial_write (struct tty_struct * tty, const unsigned char *buf, int ...@@ -1426,78 +1344,69 @@ static int serial_write (struct tty_struct * tty, const unsigned char *buf, int
mydbg("%s - port %d, %d byte(s)\n", __FUNCTION__, port->number, count); mydbg("%s - port %d, %d byte(s)\n", __FUNCTION__, port->number, count);
mydbg("%s - port->RxHolding = %d\n", __FUNCTION__, port->RxHolding); mydbg("%s - port->RxHolding = %d\n", __FUNCTION__, port->RxHolding);
if (!port->open_count) if (!port->open_count) {
{
mydbg("%s - port not opened\n", __FUNCTION__); mydbg("%s - port not opened\n", __FUNCTION__);
goto exit; goto exit;
} }
retval = qt_write(port, from_user, buf, count); retval = qt_write(port, from_user, buf, count);
exit: exit:
return retval; return retval;
} }
static int qt_write(struct usb_serial_port *port, int from_user,
static int qt_write (struct usb_serial_port *port, int from_user, const unsigned char *buf, int count){ const unsigned char *buf, int count)
{
int result; int result;
unsigned int UartNumber; unsigned int UartNumber;
struct usb_serial *serial = get_usb_serial (port, __FUNCTION__); struct usb_serial *serial = get_usb_serial(port, __FUNCTION__);
if(serial == NULL) if (serial == NULL)
return -ENODEV; return -ENODEV;
mydbg("%s - port %d\n", __FUNCTION__, port->number); mydbg("%s - port %d\n", __FUNCTION__, port->number);
if (count == 0) if (count == 0) {
{
mydbg("%s - write request of 0 bytes\n", __FUNCTION__); mydbg("%s - write request of 0 bytes\n", __FUNCTION__);
return(0); return (0);
} }
UartNumber = port->tty->index - serial->minor; UartNumber = port->tty->index - serial->minor;
/* only do something if we have a bulk out endpoint */ /* only do something if we have a bulk out endpoint */
if (serial->num_bulk_out) if (serial->num_bulk_out) {
{ if (port->write_urb->status == -EINPROGRESS) {
if (port->write_urb->status == -EINPROGRESS)
{
mydbg("%s - already writing\n", __FUNCTION__); mydbg("%s - already writing\n", __FUNCTION__);
return(0); return (0);
} }
count = (count > port->bulk_out_size) ? port->bulk_out_size : count; count =
(count > port->bulk_out_size) ? port->bulk_out_size : count;
if (from_user) if (from_user) {
{ if (copy_from_user
if (copy_from_user(port->write_urb->transfer_buffer, buf, count)) (port->write_urb->transfer_buffer, buf, count))
return -EFAULT; return -EFAULT;
} else } else {
{ memcpy(port->write_urb->transfer_buffer, buf, count);
memcpy (port->write_urb->transfer_buffer, buf, count);
} }
//usb_serial_debug_data(__FILE__, __FUNCTION__, count, port->write_urb->transfer_buffer); //usb_serial_debug_data(__FILE__, __FUNCTION__, count, port->write_urb->transfer_buffer);
/* set up our urb */ /* set up our urb */
usb_fill_bulk_urb(port->write_urb, serial->dev,
usb_fill_bulk_urb (port->write_urb, serial->dev, usb_sndbulkpipe(serial->dev,
usb_sndbulkpipe (serial->dev, port->
port->bulk_out_endpointAddress), bulk_out_endpointAddress),
port->write_urb->transfer_buffer, count, port->write_urb->transfer_buffer, count,
qt_write_bulk_callback, port); qt_write_bulk_callback, port);
/* send the data out the bulk port */ /* send the data out the bulk port */
result = usb_submit_urb(port->write_urb, GFP_ATOMIC); result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
if (result) if (result)
mydbg("%s - failed submitting write urb, error %d\n", __FUNCTION__, result); mydbg("%s - failed submitting write urb, error %d\n",
__FUNCTION__, result);
else else
result = count; result = count;
...@@ -1505,27 +1414,24 @@ static int qt_write (struct usb_serial_port *port, int from_user, const unsigned ...@@ -1505,27 +1414,24 @@ static int qt_write (struct usb_serial_port *port, int from_user, const unsigned
} }
/* no bulk out, so return 0 bytes written */ /* no bulk out, so return 0 bytes written */
return(0); return (0);
} }
static void qt_write_bulk_callback(struct urb *urb) static void qt_write_bulk_callback(struct urb *urb)
{ {
struct usb_serial_port *port = (struct usb_serial_port *)urb->context; struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
struct usb_serial *serial = get_usb_serial (port, __FUNCTION__); struct usb_serial *serial = get_usb_serial(port, __FUNCTION__);
mydbg("%s - port %d\n", __FUNCTION__, port->number); mydbg("%s - port %d\n", __FUNCTION__, port->number);
if (!serial) if (!serial) {
{
mydbg("%s - bad serial pointer, exiting\n", __FUNCTION__); mydbg("%s - bad serial pointer, exiting\n", __FUNCTION__);
return; return;
} }
if (urb->status) if (urb->status) {
{ mydbg("%s - nonzero write bulk status received: %d\n",
mydbg("%s - nonzero write bulk status received: %d\n", __FUNCTION__, urb->status); __FUNCTION__, urb->status);
return; return;
} }
// //
...@@ -1535,93 +1441,86 @@ static void qt_write_bulk_callback(struct urb *urb) ...@@ -1535,93 +1441,86 @@ static void qt_write_bulk_callback(struct urb *urb)
return; return;
} }
static void port_softint(struct work_struct *work) static void port_softint(struct work_struct *work)
{ {
struct usb_serial_port *port = struct usb_serial_port *port =
container_of(work, struct usb_serial_port, work); container_of(work, struct usb_serial_port, work);
struct usb_serial *serial = get_usb_serial (port, __FUNCTION__); struct usb_serial *serial = get_usb_serial(port, __FUNCTION__);
struct tty_struct *tty; struct tty_struct *tty;
mydbg("%s - port %d\n", __FUNCTION__, port->number); mydbg("%s - port %d\n", __FUNCTION__, port->number);
if (!serial) if (!serial)
return; return;
tty = port->tty; tty = port->tty;
if (!tty) if (!tty)
return; return;
#if 0 #if 0
if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) && tty->ldisc.write_wakeup) if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP))
{ && tty->ldisc.write_wakeup) {
mydbg("%s - write wakeup call.\n", __FUNCTION__); mydbg("%s - write wakeup call.\n", __FUNCTION__);
(tty->ldisc.write_wakeup)(tty); (tty->ldisc.write_wakeup) (tty);
} }
#endif #endif
wake_up_interruptible(&tty->write_wait); wake_up_interruptible(&tty->write_wait);
} }
static int serial_write_room (struct tty_struct *tty) static int serial_write_room(struct tty_struct *tty)
{ {
struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data; struct usb_serial_port *port =
struct usb_serial *serial = get_usb_serial (port, __FUNCTION__); (struct usb_serial_port *)tty->driver_data;
struct usb_serial *serial = get_usb_serial(port, __FUNCTION__);
int retval = -EINVAL; int retval = -EINVAL;
if (!serial) if (!serial)
return -ENODEV; return -ENODEV;
down (&port->sem); down(&port->sem);
mydbg("%s - port %d\n", __FUNCTION__, port->number); mydbg("%s - port %d\n", __FUNCTION__, port->number);
if (!port->open_count) if (!port->open_count) {
{
mydbg("%s - port not open\n", __FUNCTION__); mydbg("%s - port not open\n", __FUNCTION__);
goto exit; goto exit;
} }
retval = qt_write_room(port); retval = qt_write_room(port);
exit: exit:
up (&port->sem); up(&port->sem);
return retval; return retval;
} }
static int qt_write_room (struct usb_serial_port *port) static int qt_write_room(struct usb_serial_port *port)
{ {
struct usb_serial *serial = port->serial; struct usb_serial *serial = port->serial;
int room = 0; int room = 0;
if (port->closePending == 1) if (port->closePending == 1) {
{
mydbg("%s - port->closePending == 1\n", __FUNCTION__); mydbg("%s - port->closePending == 1\n", __FUNCTION__);
return -ENODEV; return -ENODEV;
} }
mydbg("%s - port %d\n", __FUNCTION__, port->number); mydbg("%s - port %d\n", __FUNCTION__, port->number);
if (serial->num_bulk_out) if (serial->num_bulk_out) {
{
if (port->write_urb->status != -EINPROGRESS) if (port->write_urb->status != -EINPROGRESS)
room = port->bulk_out_size; room = port->bulk_out_size;
} }
mydbg("%s - returns %d\n", __FUNCTION__, room); mydbg("%s - returns %d\n", __FUNCTION__, room);
return(room); return (room);
} }
static int serial_chars_in_buffer (struct tty_struct *tty) static int serial_chars_in_buffer(struct tty_struct *tty)
{ {
struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data; struct usb_serial_port *port =
struct usb_serial *serial = get_usb_serial (port, __FUNCTION__); (struct usb_serial_port *)tty->driver_data;
struct usb_serial *serial = get_usb_serial(port, __FUNCTION__);
int retval = -EINVAL; int retval = -EINVAL;
if (!serial) if (!serial)
return -ENODEV; return -ENODEV;
down (&port->sem); down(&port->sem);
mydbg("%s = port %d\n", __FUNCTION__, port->number); mydbg("%s = port %d\n", __FUNCTION__, port->number);
...@@ -1633,35 +1532,33 @@ static int serial_chars_in_buffer (struct tty_struct *tty) ...@@ -1633,35 +1532,33 @@ static int serial_chars_in_buffer (struct tty_struct *tty)
retval = qt_chars_in_buffer(port); retval = qt_chars_in_buffer(port);
exit: exit:
up (&port->sem); up(&port->sem);
return retval; return retval;
} }
static int qt_chars_in_buffer(struct usb_serial_port *port)
static int qt_chars_in_buffer (struct usb_serial_port *port)
{ {
struct usb_serial *serial = port->serial; struct usb_serial *serial = port->serial;
int chars = 0; int chars = 0;
mydbg("%s - port %d\n", __FUNCTION__, port->number); mydbg("%s - port %d\n", __FUNCTION__, port->number);
if (serial->num_bulk_out) if (serial->num_bulk_out) {
{
if (port->write_urb->status == -EINPROGRESS) if (port->write_urb->status == -EINPROGRESS)
chars = port->write_urb->transfer_buffer_length; chars = port->write_urb->transfer_buffer_length;
} }
mydbg("%s - returns %d\n", __FUNCTION__, chars); mydbg("%s - returns %d\n", __FUNCTION__, chars);
return(chars); return (chars);
} }
static int serial_tiocmset(struct tty_struct *tty, struct file *file,
static int serial_tiocmset (struct tty_struct *tty, struct file *file, unsigned int set, unsigned int clear) unsigned int set, unsigned int clear)
{ {
struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data; struct usb_serial_port *port =
struct usb_serial *serial = get_usb_serial (port, __FUNCTION__); (struct usb_serial_port *)tty->driver_data;
struct usb_serial *serial = get_usb_serial(port, __FUNCTION__);
int retval = -ENODEV; int retval = -ENODEV;
unsigned int UartNumber; unsigned int UartNumber;
mydbg("In %s \n", __FUNCTION__); mydbg("In %s \n", __FUNCTION__);
...@@ -1669,39 +1566,35 @@ static int serial_tiocmset (struct tty_struct *tty, struct file *file, unsigned ...@@ -1669,39 +1566,35 @@ static int serial_tiocmset (struct tty_struct *tty, struct file *file, unsigned
if (!serial) if (!serial)
return -ENODEV; return -ENODEV;
UartNumber = port->tty->index - serial->minor; UartNumber = port->tty->index - serial->minor;
down(&port->sem);
down (&port->sem);
mydbg("%s - port %d \n", __FUNCTION__, port->number); mydbg("%s - port %d \n", __FUNCTION__, port->number);
mydbg ("%s - port->RxHolding = %d\n", __FUNCTION__, port->RxHolding); mydbg("%s - port->RxHolding = %d\n", __FUNCTION__, port->RxHolding);
if (!port->open_count) if (!port->open_count) {
{ mydbg("%s - port not open\n", __FUNCTION__);
mydbg ("%s - port not open\n", __FUNCTION__);
goto exit; goto exit;
} }
retval = qt_tiocmset(port, file, set); retval = qt_tiocmset(port, file, set);
exit: exit:
up (&port->sem); up(&port->sem);
return retval; return retval;
} }
static int qt_tiocmset(struct usb_serial_port *port, struct file *file,
static int qt_tiocmset(struct usb_serial_port *port, struct file * file, unsigned int value) unsigned int value)
{ {
__u8 MCR_Value; __u8 MCR_Value;
int status; int status;
unsigned int UartNumber; unsigned int UartNumber;
struct usb_serial *serial = get_usb_serial(port, __FUNCTION__);
struct usb_serial *serial = get_usb_serial (port, __FUNCTION__); if (serial == NULL)
if(serial == NULL)
return -ENODEV; return -ENODEV;
mydbg("%s - port %d\n", __FUNCTION__, port->number); mydbg("%s - port %d\n", __FUNCTION__, port->number);
...@@ -1710,7 +1603,9 @@ static int qt_tiocmset(struct usb_serial_port *port, struct file * file, unsigne ...@@ -1710,7 +1603,9 @@ static int qt_tiocmset(struct usb_serial_port *port, struct file * file, unsigne
/** TIOCMGET /** TIOCMGET
*/ */
UartNumber = port->tty->index - serial->minor; UartNumber = port->tty->index - serial->minor;
status = BoxGetRegister(port->serial, UartNumber, MODEM_CONTROL_REGISTER, &MCR_Value); status =
BoxGetRegister(port->serial, UartNumber, MODEM_CONTROL_REGISTER,
&MCR_Value);
if (status < 0) if (status < 0)
return -ESPIPE; return -ESPIPE;
...@@ -1724,7 +1619,9 @@ static int qt_tiocmset(struct usb_serial_port *port, struct file * file, unsigne ...@@ -1724,7 +1619,9 @@ static int qt_tiocmset(struct usb_serial_port *port, struct file * file, unsigne
if (value & TIOCM_LOOP) if (value & TIOCM_LOOP)
MCR_Value |= SERIAL_MCR_LOOP; MCR_Value |= SERIAL_MCR_LOOP;
status = BoxSetRegister(port->serial, UartNumber, MODEM_CONTROL_REGISTER, MCR_Value); status =
BoxSetRegister(port->serial, UartNumber, MODEM_CONTROL_REGISTER,
MCR_Value);
if (status < 0) if (status < 0)
return -ESPIPE; return -ESPIPE;
else else
...@@ -1734,9 +1631,10 @@ static int qt_tiocmset(struct usb_serial_port *port, struct file * file, unsigne ...@@ -1734,9 +1631,10 @@ static int qt_tiocmset(struct usb_serial_port *port, struct file * file, unsigne
static int serial_tiocmget(struct tty_struct *tty, struct file *file) static int serial_tiocmget(struct tty_struct *tty, struct file *file)
{ {
struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data; struct usb_serial_port *port =
(struct usb_serial_port *)tty->driver_data;
struct usb_serial *serial = get_usb_serial (port, __FUNCTION__); struct usb_serial *serial = get_usb_serial(port, __FUNCTION__);
int retval = -ENODEV; int retval = -ENODEV;
unsigned int UartNumber; unsigned int UartNumber;
mydbg("In %s \n", __FUNCTION__); mydbg("In %s \n", __FUNCTION__);
...@@ -1744,31 +1642,26 @@ static int serial_tiocmget(struct tty_struct *tty, struct file *file) ...@@ -1744,31 +1642,26 @@ static int serial_tiocmget(struct tty_struct *tty, struct file *file)
if (!serial) if (!serial)
return -ENODEV; return -ENODEV;
UartNumber = port->tty->index - serial->minor; UartNumber = port->tty->index - serial->minor;
down(&port->sem);
down (&port->sem);
mydbg("%s - port %d\n", __FUNCTION__, port->number); mydbg("%s - port %d\n", __FUNCTION__, port->number);
mydbg ("%s - port->RxHolding = %d\n", __FUNCTION__, port->RxHolding); mydbg("%s - port->RxHolding = %d\n", __FUNCTION__, port->RxHolding);
if (!port->open_count) if (!port->open_count) {
{ mydbg("%s - port not open\n", __FUNCTION__);
mydbg ("%s - port not open\n", __FUNCTION__);
goto exit; goto exit;
} }
retval = qt_tiocmget(port, file); retval = qt_tiocmget(port, file);
exit: exit:
up (&port->sem); up(&port->sem);
return retval; return retval;
} }
static int qt_tiocmget(struct usb_serial_port *port, struct file *file)
static int qt_tiocmget(struct usb_serial_port *port, struct file * file)
{ {
__u8 MCR_Value; __u8 MCR_Value;
...@@ -1776,11 +1669,10 @@ static int qt_tiocmget(struct usb_serial_port *port, struct file * file) ...@@ -1776,11 +1669,10 @@ static int qt_tiocmget(struct usb_serial_port *port, struct file * file)
unsigned int result = 0; unsigned int result = 0;
int status; int status;
unsigned int UartNumber; unsigned int UartNumber;
struct tty_struct * tty; struct tty_struct *tty;
struct usb_serial *serial = get_usb_serial (port, __FUNCTION__); struct usb_serial *serial = get_usb_serial(port, __FUNCTION__);
if(serial == NULL) if (serial == NULL)
return -ENODEV; return -ENODEV;
tty = port->tty; tty = port->tty;
...@@ -1790,42 +1682,43 @@ static int qt_tiocmget(struct usb_serial_port *port, struct file * file) ...@@ -1790,42 +1682,43 @@ static int qt_tiocmget(struct usb_serial_port *port, struct file * file)
/** TIOCMGET /** TIOCMGET
*/ */
UartNumber = port->tty->index - serial->minor; UartNumber = port->tty->index - serial->minor;
status = BoxGetRegister(port->serial, UartNumber, MODEM_CONTROL_REGISTER, &MCR_Value); status =
if (status >= 0) BoxGetRegister(port->serial, UartNumber, MODEM_CONTROL_REGISTER,
{ &MCR_Value);
status = BoxGetRegister(port->serial, UartNumber, MODEM_STATUS_REGISTER, &MSR_Value); if (status >= 0) {
status =
BoxGetRegister(port->serial, UartNumber,
MODEM_STATUS_REGISTER, &MSR_Value);
} }
if (status >= 0) if (status >= 0) {
{ result = ((MCR_Value & SERIAL_MCR_DTR) ? TIOCM_DTR : 0)
result = ((MCR_Value & SERIAL_MCR_DTR) ? TIOCM_DTR: 0)
//DTR IS SET //DTR IS SET
| ((MCR_Value & SERIAL_MCR_RTS) ? TIOCM_RTS: 0) | ((MCR_Value & SERIAL_MCR_RTS) ? TIOCM_RTS : 0)
//RTS IS SET //RTS IS SET
| ((MSR_Value & SERIAL_MSR_CTS) ? TIOCM_CTS: 0) | ((MSR_Value & SERIAL_MSR_CTS) ? TIOCM_CTS : 0)
//CTS is set //CTS is set
| ((MSR_Value & SERIAL_MSR_CD) ? TIOCM_CAR: 0) | ((MSR_Value & SERIAL_MSR_CD) ? TIOCM_CAR : 0)
//Carrier detect is set //Carrier detect is set
| ((MSR_Value & SERIAL_MSR_RI) ? TIOCM_RI: 0) | ((MSR_Value & SERIAL_MSR_RI) ? TIOCM_RI : 0)
//Ring indicator set //Ring indicator set
| ((MSR_Value & SERIAL_MSR_DSR) ? TIOCM_DSR: 0); | ((MSR_Value & SERIAL_MSR_DSR) ? TIOCM_DSR : 0);
//DSR is set //DSR is set
return result; return result;
} } else
else
return -ESPIPE; return -ESPIPE;
//endif tatus => 0 //endif tatus => 0
} }
static int serial_ioctl(struct tty_struct *tty, struct file *file,
unsigned int cmd, unsigned long arg)
static int serial_ioctl (struct tty_struct *tty, struct file * file, unsigned int cmd, unsigned long arg)
{ {
struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data; struct usb_serial_port *port =
struct usb_serial *serial = get_usb_serial (port, __FUNCTION__); (struct usb_serial_port *)tty->driver_data;
struct usb_serial *serial = get_usb_serial(port, __FUNCTION__);
int retval = -ENODEV; int retval = -ENODEV;
unsigned int UartNumber; unsigned int UartNumber;
mydbg("In %s \n", __FUNCTION__); mydbg("In %s \n", __FUNCTION__);
...@@ -1833,28 +1726,26 @@ static int serial_ioctl (struct tty_struct *tty, struct file * file, unsigned in ...@@ -1833,28 +1726,26 @@ static int serial_ioctl (struct tty_struct *tty, struct file * file, unsigned in
if (!serial) if (!serial)
return -ENODEV; return -ENODEV;
UartNumber = port->tty->index - serial->minor; UartNumber = port->tty->index - serial->minor;
down(&port->sem);
down (&port->sem);
mydbg("%s - port %d, cmd 0x%.4x\n", __FUNCTION__, port->number, cmd); mydbg("%s - port %d, cmd 0x%.4x\n", __FUNCTION__, port->number, cmd);
mydbg ("%s - port->RxHolding = %d\n", __FUNCTION__, port->RxHolding); mydbg("%s - port->RxHolding = %d\n", __FUNCTION__, port->RxHolding);
if (!port->open_count) if (!port->open_count) {
{ mydbg("%s - port not open\n", __FUNCTION__);
mydbg ("%s - port not open\n", __FUNCTION__);
goto exit; goto exit;
} }
retval = qt_ioctl(port, file, cmd, arg); retval = qt_ioctl(port, file, cmd, arg);
exit: exit:
up (&port->sem); up(&port->sem);
return retval; return retval;
} }
static int qt_ioctl(struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg) static int qt_ioctl(struct usb_serial_port *port, struct file *file,
unsigned int cmd, unsigned long arg)
{ {
__u8 MCR_Value; __u8 MCR_Value;
__u8 MSR_Value; __u8 MSR_Value;
...@@ -1862,11 +1753,10 @@ static int qt_ioctl(struct usb_serial_port *port, struct file * file, unsigned i ...@@ -1862,11 +1753,10 @@ static int qt_ioctl(struct usb_serial_port *port, struct file * file, unsigned i
unsigned int value, result = 0; unsigned int value, result = 0;
int status; int status;
unsigned int UartNumber; unsigned int UartNumber;
struct tty_struct * tty; struct tty_struct *tty;
struct usb_serial *serial = get_usb_serial (port, __FUNCTION__); struct usb_serial *serial = get_usb_serial(port, __FUNCTION__);
if(serial == NULL) if (serial == NULL)
return -ENODEV; return -ENODEV;
tty = port->tty; tty = port->tty;
...@@ -1877,31 +1767,32 @@ static int qt_ioctl(struct usb_serial_port *port, struct file * file, unsigned i ...@@ -1877,31 +1767,32 @@ static int qt_ioctl(struct usb_serial_port *port, struct file * file, unsigned i
*/ */
UartNumber = port->tty->index - serial->minor; UartNumber = port->tty->index - serial->minor;
if(cmd == TIOCMGET) if (cmd == TIOCMGET) {
{
MCR_Value = port->shadowMCR; MCR_Value = port->shadowMCR;
MSR_Value = port->shadowMSR; MSR_Value = port->shadowMSR;
{ {
result = ((MCR_Value & SERIAL_MCR_DTR) ? TIOCM_DTR: 0) result = ((MCR_Value & SERIAL_MCR_DTR) ? TIOCM_DTR : 0)
//DTR IS SET //DTR IS SET
| ((MCR_Value & SERIAL_MCR_RTS) ? TIOCM_RTS: 0) | ((MCR_Value & SERIAL_MCR_RTS) ? TIOCM_RTS : 0)
//RTS IS SET //RTS IS SET
| ((MSR_Value & SERIAL_MSR_CTS) ? TIOCM_CTS: 0) | ((MSR_Value & SERIAL_MSR_CTS) ? TIOCM_CTS : 0)
//CTS is set //CTS is set
| ((MSR_Value & SERIAL_MSR_CD) ? TIOCM_CAR: 0) | ((MSR_Value & SERIAL_MSR_CD) ? TIOCM_CAR : 0)
//Carrier detect is set //Carrier detect is set
| ((MSR_Value & SERIAL_MSR_RI) ? TIOCM_RI: 0) | ((MSR_Value & SERIAL_MSR_RI) ? TIOCM_RI : 0)
//Ring indicator set //Ring indicator set
| ((MSR_Value & SERIAL_MSR_DSR) ? TIOCM_DSR: 0); | ((MSR_Value & SERIAL_MSR_DSR) ? TIOCM_DSR : 0);
//DSR is set //DSR is set
if(copy_to_user((unsigned int *)arg, &result, sizeof(unsigned int))) if (copy_to_user
((unsigned int *)arg, &result,
sizeof(unsigned int)))
return -EFAULT; return -EFAULT;
return 0; return 0;
}//endif tatus => 0 } //endif tatus => 0
}//endif(cmd == TIOCMGET) } //endif(cmd == TIOCMGET)
/**************************************************************************************/ /**************************************************************************************/
/** End TIOCMGET /** End TIOCMGET
*/ */
...@@ -1910,16 +1801,17 @@ static int qt_ioctl(struct usb_serial_port *port, struct file * file, unsigned i ...@@ -1910,16 +1801,17 @@ static int qt_ioctl(struct usb_serial_port *port, struct file * file, unsigned i
/**************************************************************************************/ /**************************************************************************************/
if(cmd == TIOCMBIS || cmd == TIOCMBIC || cmd == TIOCMSET) if (cmd == TIOCMBIS || cmd == TIOCMBIC || cmd == TIOCMSET) {
{ status =
status = BoxGetRegister(port->serial, UartNumber, MODEM_CONTROL_REGISTER, &MCR_Value); BoxGetRegister(port->serial, UartNumber,
MODEM_CONTROL_REGISTER, &MCR_Value);
if (status < 0) if (status < 0)
return -ESPIPE; return -ESPIPE;
if (copy_from_user(&value, (unsigned int *)arg, sizeof(unsigned int))) if (copy_from_user
(&value, (unsigned int *)arg, sizeof(unsigned int)))
return -EFAULT; return -EFAULT;
switch (cmd) switch (cmd) {
{
case TIOCMBIS: case TIOCMBIS:
if (value & TIOCM_RTS) if (value & TIOCM_RTS)
MCR_Value |= SERIAL_MCR_RTS; MCR_Value |= SERIAL_MCR_RTS;
...@@ -1939,7 +1831,9 @@ static int qt_ioctl(struct usb_serial_port *port, struct file * file, unsigned i ...@@ -1939,7 +1831,9 @@ static int qt_ioctl(struct usb_serial_port *port, struct file * file, unsigned i
case TIOCMSET: case TIOCMSET:
//Turn off the RTS and DTR and loopbcck and then only //Turn off the RTS and DTR and loopbcck and then only
//trun on what was asked for //trun on what was asked for
MCR_Value &= ~(SERIAL_MCR_RTS | SERIAL_MCR_DTR | SERIAL_MCR_LOOP); MCR_Value &=
~(SERIAL_MCR_RTS | SERIAL_MCR_DTR |
SERIAL_MCR_LOOP);
if (value & TIOCM_RTS) if (value & TIOCM_RTS)
MCR_Value |= SERIAL_MCR_RTS; MCR_Value |= SERIAL_MCR_RTS;
if (value & TIOCM_DTR) if (value & TIOCM_DTR)
...@@ -1951,69 +1845,71 @@ static int qt_ioctl(struct usb_serial_port *port, struct file * file, unsigned i ...@@ -1951,69 +1845,71 @@ static int qt_ioctl(struct usb_serial_port *port, struct file * file, unsigned i
break; break;
} }
status = BoxSetRegister(port->serial, UartNumber, MODEM_CONTROL_REGISTER, MCR_Value); status =
BoxSetRegister(port->serial, UartNumber,
MODEM_CONTROL_REGISTER, MCR_Value);
if (status < 0) if (status < 0)
return -ESPIPE; return -ESPIPE;
else else {
{
port->shadowMCR = MCR_Value; port->shadowMCR = MCR_Value;
return 0; return 0;
} }
} }
/**************************************************************************************/ /**************************************************************************************/
/** TIOCMBIS, TIOCMBIC, AND TIOCMSET end /** TIOCMBIS, TIOCMBIC, AND TIOCMSET end
*/ */
/**************************************************************************************/ /**************************************************************************************/
if(cmd == TIOCMIWAIT) if (cmd == TIOCMIWAIT) {
{
DECLARE_WAITQUEUE(wait, current); DECLARE_WAITQUEUE(wait, current);
Prev_MSR_Value = port->shadowMSR & SERIAL_MSR_MASK; Prev_MSR_Value = port->shadowMSR & SERIAL_MSR_MASK;
while(1) while (1) {
{
add_wait_queue(&port->wait, &wait); add_wait_queue(&port->wait, &wait);
set_current_state(TASK_INTERRUPTIBLE); set_current_state(TASK_INTERRUPTIBLE);
schedule(); schedule();
remove_wait_queue(&port->wait, &wait); remove_wait_queue(&port->wait, &wait);
/* see if a signal woke us up */ /* see if a signal woke us up */
if(signal_pending(current)) if (signal_pending(current))
return -ERESTARTSYS; return -ERESTARTSYS;
MSR_Value = port->shadowMSR & SERIAL_MSR_MASK; MSR_Value = port->shadowMSR & SERIAL_MSR_MASK;
if(MSR_Value == Prev_MSR_Value) if (MSR_Value == Prev_MSR_Value)
return -EIO; //no change error return -EIO; //no change error
if((arg & TIOCM_RNG && ((Prev_MSR_Value & SERIAL_MSR_RI) == if ((arg & TIOCM_RNG
(MSR_Value & SERIAL_MSR_RI))) || && ((Prev_MSR_Value & SERIAL_MSR_RI) ==
(arg & TIOCM_DSR && ((Prev_MSR_Value & SERIAL_MSR_DSR) == (MSR_Value & SERIAL_MSR_RI)))
(MSR_Value & SERIAL_MSR_DSR))) || || (arg & TIOCM_DSR
(arg & TIOCM_CD && ((Prev_MSR_Value & SERIAL_MSR_CD) == && ((Prev_MSR_Value & SERIAL_MSR_DSR) ==
(MSR_Value & SERIAL_MSR_CD))) || (MSR_Value & SERIAL_MSR_DSR)))
(arg & TIOCM_CTS && ((Prev_MSR_Value & SERIAL_MSR_CTS) == || (arg & TIOCM_CD
(MSR_Value & SERIAL_MSR_CTS)))) && ((Prev_MSR_Value & SERIAL_MSR_CD) ==
{ (MSR_Value & SERIAL_MSR_CD)))
|| (arg & TIOCM_CTS
&& ((Prev_MSR_Value & SERIAL_MSR_CTS) ==
(MSR_Value & SERIAL_MSR_CTS)))) {
return 0; return 0;
} }
}//endwhile } //endwhile
} }
mydbg("%s -No ioctl for that one. port = %d\n", __FUNCTION__, port->number); mydbg("%s -No ioctl for that one. port = %d\n", __FUNCTION__,
port->number);
return -ENOIOCTLCMD; return -ENOIOCTLCMD;
} }
static void serial_set_termios (struct tty_struct *tty, struct ktermios *old) static void serial_set_termios(struct tty_struct *tty, struct ktermios *old)
{ {
struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data; struct usb_serial_port *port =
struct usb_serial *serial = get_usb_serial (port, __FUNCTION__); (struct usb_serial_port *)tty->driver_data;
struct usb_serial *serial = get_usb_serial(port, __FUNCTION__);
if (!serial) if (!serial)
return; return;
down (&port->sem); down(&port->sem);
mydbg("%s - port %d\n", __FUNCTION__, port->number); mydbg("%s - port %d\n", __FUNCTION__, port->number);
...@@ -2026,10 +1922,11 @@ static void serial_set_termios (struct tty_struct *tty, struct ktermios *old) ...@@ -2026,10 +1922,11 @@ static void serial_set_termios (struct tty_struct *tty, struct ktermios *old)
qt_set_termios(port, old); qt_set_termios(port, old);
exit: exit:
up (&port->sem); up(&port->sem);
} }
static void qt_set_termios(struct usb_serial_port *port, struct ktermios *old_termios) static void qt_set_termios(struct usb_serial_port *port,
struct ktermios *old_termios)
{ {
unsigned int cflag; unsigned int cflag;
int baud, divisor, remainder; int baud, divisor, remainder;
...@@ -2045,35 +1942,29 @@ static void qt_set_termios(struct usb_serial_port *port, struct ktermios *old_te ...@@ -2045,35 +1942,29 @@ static void qt_set_termios(struct usb_serial_port *port, struct ktermios *old_te
tmp = port->tty->index; tmp = port->tty->index;
mydbg("%s - MINOR(port->tty->index) = %d\n", __FUNCTION__, tmp); mydbg("%s - MINOR(port->tty->index) = %d\n", __FUNCTION__, tmp);
serial = port->serial; serial = port->serial;
tmp2 = serial->minor; tmp2 = serial->minor;
mydbg("%s - serial->minor = %d\n", __FUNCTION__, tmp2); mydbg("%s - serial->minor = %d\n", __FUNCTION__, tmp2);
UartNumber = port->tty->index - serial->minor; UartNumber = port->tty->index - serial->minor;
tty = port->tty; tty = port->tty;
cflag = tty->termios->c_cflag; cflag = tty->termios->c_cflag;
if (old_termios) if (old_termios) {
{ if ((cflag == old_termios->c_cflag)
if((cflag == old_termios->c_cflag) && (RELEVANT_IFLAG(tty->termios->c_iflag) == && (RELEVANT_IFLAG(tty->termios->c_iflag) ==
RELEVANT_IFLAG(old_termios->c_iflag))) RELEVANT_IFLAG(old_termios->c_iflag))) {
{
mydbg("%s - Nothing to change\n", __FUNCTION__); mydbg("%s - Nothing to change\n", __FUNCTION__);
return; return;
} }
} }
mydbg("%s - 3\n", __FUNCTION__); mydbg("%s - 3\n", __FUNCTION__);
switch(cflag) switch (cflag) {
{
case CS5: case CS5:
LCR_change_to |= SERIAL_5_DATA; LCR_change_to |= SERIAL_5_DATA;
break; break;
...@@ -2090,14 +1981,13 @@ static void qt_set_termios(struct usb_serial_port *port, struct ktermios *old_te ...@@ -2090,14 +1981,13 @@ static void qt_set_termios(struct usb_serial_port *port, struct ktermios *old_te
} }
//Parity stuff //Parity stuff
if(cflag & PARENB) if (cflag & PARENB) {
{ if (cflag & PARODD)
if(cflag & PARODD)
LCR_change_to |= SERIAL_ODD_PARITY; LCR_change_to |= SERIAL_ODD_PARITY;
else else
LCR_change_to |= SERIAL_EVEN_PARITY; LCR_change_to |= SERIAL_EVEN_PARITY;
} }
if(cflag & CSTOPB) if (cflag & CSTOPB)
LCR_change_to |= SERIAL_TWO_STOPB; LCR_change_to |= SERIAL_TWO_STOPB;
else else
LCR_change_to |= SERIAL_TWO_STOPB; LCR_change_to |= SERIAL_TWO_STOPB;
...@@ -2112,104 +2002,99 @@ static void qt_set_termios(struct usb_serial_port *port, struct ktermios *old_te ...@@ -2112,104 +2002,99 @@ static void qt_set_termios(struct usb_serial_port *port, struct ktermios *old_te
mydbg("%s - got baud = %d\n", __FUNCTION__, baud); mydbg("%s - got baud = %d\n", __FUNCTION__, baud);
divisor = MAX_BAUD_RATE / baud; divisor = MAX_BAUD_RATE / baud;
remainder = MAX_BAUD_RATE % baud; remainder = MAX_BAUD_RATE % baud;
//Round to nearest divisor //Round to nearest divisor
if(((remainder * 2) >= baud) && (baud != 110)) if (((remainder * 2) >= baud) && (baud != 110))
divisor++; divisor++;
//Set Baud rate to default and turn off (default)flow control here //Set Baud rate to default and turn off (default)flow control here
status = BoxSetUart(serial, UartNumber, (unsigned short) divisor, LCR_change_to); status =
if (status < 0) BoxSetUart(serial, UartNumber, (unsigned short)divisor,
{ LCR_change_to);
mydbg(__FILE__"BoxSetUart failed\n"); if (status < 0) {
mydbg(__FILE__ "BoxSetUart failed\n");
return; return;
} }
//************************Now determine flow control //************************Now determine flow control
if(cflag & CRTSCTS) if (cflag & CRTSCTS) {
{ mydbg("%s - Enabling HW flow control port %d\n", __FUNCTION__,
mydbg("%s - Enabling HW flow control port %d\n", __FUNCTION__, port->number); port->number);
//Enable RTS/CTS flow control //Enable RTS/CTS flow control
status = BoxSetHW_FlowCtrl(serial, UartNumber, 1); status = BoxSetHW_FlowCtrl(serial, UartNumber, 1);
if (status < 0) if (status < 0) {
{ mydbg(__FILE__ "BoxSetHW_FlowCtrl failed\n");
mydbg(__FILE__"BoxSetHW_FlowCtrl failed\n");
return; return;
} }
} } else {
else
{
//Disable RTS/CTS flow control //Disable RTS/CTS flow control
mydbg("%s - disabling HW flow control port %d\n", __FUNCTION__, port->number); mydbg("%s - disabling HW flow control port %d\n", __FUNCTION__,
port->number);
status = BoxSetHW_FlowCtrl(serial, UartNumber, 0); status = BoxSetHW_FlowCtrl(serial, UartNumber, 0);
if (status < 0) if (status < 0) {
{ mydbg(__FILE__ "BoxSetHW_FlowCtrl failed\n");
mydbg(__FILE__"BoxSetHW_FlowCtrl failed\n");
return; return;
} }
} }
//************************************************* //*************************************************
/* if we are implementing XON/XOFF, set the start and stop character in the device */ /* if we are implementing XON/XOFF, set the start and stop character in the device */
if (I_IXOFF(tty) || I_IXON(tty)) if (I_IXOFF(tty) || I_IXON(tty)) {
{
unsigned char stop_char = STOP_CHAR(tty); unsigned char stop_char = STOP_CHAR(tty);
unsigned char start_char = START_CHAR(tty); unsigned char start_char = START_CHAR(tty);
status = BoxSetSW_FlowCtrl(serial, UartNumber, stop_char, start_char); status =
if(status < 0) BoxSetSW_FlowCtrl(serial, UartNumber, stop_char,
mydbg(__FILE__"BoxSetSW_FlowCtrl (enabled) failed\n"); start_char);
if (status < 0)
mydbg(__FILE__ "BoxSetSW_FlowCtrl (enabled) failed\n");
} } else {
else
{
//disable SW flow control //disable SW flow control
status = BoxDisable_SW_FlowCtrl(serial, UartNumber); status = BoxDisable_SW_FlowCtrl(serial, UartNumber);
if(status < 0) if (status < 0)
mydbg(__FILE__"BoxSetSW_FlowCtrl (diabling) failed\n"); mydbg(__FILE__ "BoxSetSW_FlowCtrl (diabling) failed\n");
} }
} }
/**************************************************************************** /****************************************************************************
* BoxGetRegister * BoxGetRegister
* issuse a GET_REGISTER vendor-spcific request on the default control pipe * issuse a GET_REGISTER vendor-spcific request on the default control pipe
* If successful, fills in the pValue with the register value asked for * If successful, fills in the pValue with the register value asked for
****************************************************************************/ ****************************************************************************/
static int BoxGetRegister(struct usb_serial *serial, unsigned short Uart_Number, static int BoxGetRegister(struct usb_serial *serial, unsigned short Uart_Number,
unsigned short Register_Num, __u8 *pValue ) unsigned short Register_Num, __u8 * pValue)
{ {
int result; int result;
__u16 current_length; __u16 current_length;
current_length = sizeof(struct qt_get_device_data); current_length = sizeof(struct qt_get_device_data);
result = usb_control_msg (serial->dev, usb_rcvctrlpipe(serial->dev, 0), QT_GET_SET_REGISTER, result =
0xC0, Register_Num, Uart_Number, (void *)pValue, sizeof(*pValue), 300); usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
QT_GET_SET_REGISTER, 0xC0, Register_Num,
Uart_Number, (void *)pValue, sizeof(*pValue), 300);
return result; return result;
} }
/**************************************************************************** /****************************************************************************
* BoxSetRegister * BoxSetRegister
* issuse a GET_REGISTER vendor-spcific request on the default control pipe * issuse a GET_REGISTER vendor-spcific request on the default control pipe
* If successful, fills in the pValue with the register value asked for * If successful, fills in the pValue with the register value asked for
****************************************************************************/ ****************************************************************************/
static int BoxSetRegister(struct usb_serial *serial, unsigned short Uart_Number, static int BoxSetRegister(struct usb_serial *serial, unsigned short Uart_Number,
unsigned short Register_Num, unsigned short Value ) unsigned short Register_Num, unsigned short Value)
{ {
int result; int result;
unsigned short RegAndByte; unsigned short RegAndByte;
RegAndByte = Value; RegAndByte = Value;
RegAndByte = RegAndByte << 8; RegAndByte = RegAndByte << 8;
RegAndByte = RegAndByte + Register_Num; RegAndByte = RegAndByte + Register_Num;
...@@ -2217,16 +2102,14 @@ static int BoxSetRegister(struct usb_serial *serial, unsigned short Uart_Number ...@@ -2217,16 +2102,14 @@ static int BoxSetRegister(struct usb_serial *serial, unsigned short Uart_Number
// result = usb_control_msg (serial->dev, usb_sndctrlpipe(serial->dev, 0), QT_GET_SET_REGISTER, // result = usb_control_msg (serial->dev, usb_sndctrlpipe(serial->dev, 0), QT_GET_SET_REGISTER,
// 0xC0, Register_Num, Uart_Number, NULL, 0, 300); // 0xC0, Register_Num, Uart_Number, NULL, 0, 300);
result =
result = usb_control_msg (serial->dev, usb_sndctrlpipe(serial->dev, 0), QT_GET_SET_REGISTER, usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
0x40, RegAndByte, Uart_Number, NULL,0, 300); QT_GET_SET_REGISTER, 0x40, RegAndByte, Uart_Number,
NULL, 0, 300);
return result; return result;
} }
/** /**
* box_get_device * box_get_device
* Issue a GET_DEVICE vendor-specific request on the default control pipe If * Issue a GET_DEVICE vendor-specific request on the default control pipe If
...@@ -2261,15 +2144,16 @@ static int box_get_device(struct usb_serial *serial, ...@@ -2261,15 +2144,16 @@ static int box_get_device(struct usb_serial *serial,
* successful returns the number of bytes written, otherwise it returns a * successful returns the number of bytes written, otherwise it returns a
* negative error number of the problem. * negative error number of the problem.
*/ */
static int box_set_device(struct usb_serial *serial, struct qt_get_device_data *device_data) static int box_set_device(struct usb_serial *serial,
struct qt_get_device_data *device_data)
{ {
int result; int result;
__u16 length; __u16 length;
__u16 PortSettings; __u16 PortSettings;
PortSettings = ((__u16)(device_data->portb)); PortSettings = ((__u16) (device_data->portb));
PortSettings = (PortSettings << 8); PortSettings = (PortSettings << 8);
PortSettings += ((__u16)(device_data->porta)); PortSettings += ((__u16) (device_data->porta));
length = sizeof(struct qt_get_device_data); length = sizeof(struct qt_get_device_data);
mydbg("%s - PortSettings = 0x%x\n", __FUNCTION__, PortSettings); mydbg("%s - PortSettings = 0x%x\n", __FUNCTION__, PortSettings);
...@@ -2286,7 +2170,9 @@ static int box_set_device(struct usb_serial *serial, struct qt_get_device_data * ...@@ -2286,7 +2170,9 @@ static int box_set_device(struct usb_serial *serial, struct qt_get_device_data *
* purpose is to allow the device driver and the device to synchronize state information. * purpose is to allow the device driver and the device to synchronize state information.
* OpenClose = 1 for open , 0 for close * OpenClose = 1 for open , 0 for close
****************************************************************************/ ****************************************************************************/
static int BoxOPenCloseChannel(struct usb_serial *serial, __u16 Uart_Number, __u16 OpenClose, struct qt_open_channel_data *pDeviceData) static int BoxOPenCloseChannel(struct usb_serial *serial, __u16 Uart_Number,
__u16 OpenClose,
struct qt_open_channel_data *pDeviceData)
{ {
int result; int result;
__u16 length; __u16 length;
...@@ -2298,22 +2184,21 @@ static int BoxOPenCloseChannel(struct usb_serial *serial, __u16 Uart_Number, __u ...@@ -2298,22 +2184,21 @@ static int BoxOPenCloseChannel(struct usb_serial *serial, __u16 Uart_Number, __u
{ {
Direcion = USBD_TRANSFER_DIRECTION_IN; Direcion = USBD_TRANSFER_DIRECTION_IN;
pipe = usb_rcvctrlpipe(serial->dev, 0); pipe = usb_rcvctrlpipe(serial->dev, 0);
result = usb_control_msg (serial->dev, pipe, QT_OPEN_CLOSE_CHANNEL, result =
Direcion, OpenClose, Uart_Number, pDeviceData, length, 300); usb_control_msg(serial->dev, pipe, QT_OPEN_CLOSE_CHANNEL,
Direcion, OpenClose, Uart_Number,
pDeviceData, length, 300);
} else {
}
else
{
Direcion = USBD_TRANSFER_DIRECTION_OUT; Direcion = USBD_TRANSFER_DIRECTION_OUT;
pipe = usb_sndctrlpipe(serial->dev, 0); pipe = usb_sndctrlpipe(serial->dev, 0);
result = usb_control_msg (serial->dev, pipe, QT_OPEN_CLOSE_CHANNEL, result =
Direcion, OpenClose, Uart_Number, NULL, 0, 300); usb_control_msg(serial->dev, pipe, QT_OPEN_CLOSE_CHANNEL,
Direcion, OpenClose, Uart_Number, NULL, 0,
300);
} }
return result; return result;
} }
...@@ -2333,8 +2218,6 @@ static int BoxSetPrebufferLevel(struct usb_serial *serial) ...@@ -2333,8 +2218,6 @@ static int BoxSetPrebufferLevel(struct usb_serial *serial)
return result; return result;
} }
/**************************************************************************** /****************************************************************************
* BoxSetATC * BoxSetATC
TELLS BOX WHEN TO ASSERT automatic transmitter control TELLS BOX WHEN TO ASSERT automatic transmitter control
...@@ -2344,11 +2227,11 @@ static int BoxSetATC(struct usb_serial *serial, __u16 n_Mode) ...@@ -2344,11 +2227,11 @@ static int BoxSetATC(struct usb_serial *serial, __u16 n_Mode)
int result; int result;
__u16 buffer_length; __u16 buffer_length;
buffer_length = PREFUFF_LEVEL_CONSERVATIVE; buffer_length = PREFUFF_LEVEL_CONSERVATIVE;
result = usb_control_msg (serial->dev, usb_sndctrlpipe(serial->dev, 0), QT_SET_ATF, result =
0x40, n_Mode, 0, NULL, 0, 300); usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
QT_SET_ATF, 0x40, n_Mode, 0, NULL, 0, 300);
return result; return result;
} }
...@@ -2359,21 +2242,23 @@ static int BoxSetATC(struct usb_serial *serial, __u16 n_Mode) ...@@ -2359,21 +2242,23 @@ static int BoxSetATC(struct usb_serial *serial, __u16 n_Mode)
* If successful sets baud rate divisor and LCR value * If successful sets baud rate divisor and LCR value
****************************************************************************/ ****************************************************************************/
static int BoxSetUart(struct usb_serial *serial, unsigned short Uart_Number, static int BoxSetUart(struct usb_serial *serial, unsigned short Uart_Number,
unsigned short default_divisor, unsigned char default_LCR ) unsigned short default_divisor, unsigned char default_LCR)
{ {
int result; int result;
unsigned short UartNumandLCR; unsigned short UartNumandLCR;
UartNumandLCR = (default_LCR << 8) + Uart_Number; UartNumandLCR = (default_LCR << 8) + Uart_Number;
result = usb_control_msg (serial->dev, usb_sndctrlpipe(serial->dev, 0), QT_GET_SET_UART, result =
0x40, default_divisor, UartNumandLCR, NULL, 0, 300); usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
QT_GET_SET_UART, 0x40, default_divisor,
UartNumandLCR, NULL, 0, 300);
return result; return result;
} }
static int BoxSetHW_FlowCtrl(struct usb_serial *serial, unsigned int UartNumber,
static int BoxSetHW_FlowCtrl(struct usb_serial *serial, unsigned int UartNumber, int bSet) int bSet)
{ {
__u8 MCR_Value = 0; __u8 MCR_Value = 0;
__u8 MSR_Value = 0, MOUT_Value = 0; __u8 MSR_Value = 0, MOUT_Value = 0;
...@@ -2382,36 +2267,32 @@ static int BoxSetHW_FlowCtrl(struct usb_serial *serial, unsigned int UartNumber ...@@ -2382,36 +2267,32 @@ static int BoxSetHW_FlowCtrl(struct usb_serial *serial, unsigned int UartNumber
port = serial->port; port = serial->port;
if (bSet == 1) if (bSet == 1) {
{
MCR_Value = SERIAL_MCR_RTS; //flow control, box will clear RTS line to prevent remote MCR_Value = SERIAL_MCR_RTS; //flow control, box will clear RTS line to prevent remote
} //device from xmitting more chars } //device from xmitting more chars
else else { //no flow control to remote device
{ //no flow control to remote device
MCR_Value = 0; MCR_Value = 0;
} }
MOUT_Value = MCR_Value << 8; MOUT_Value = MCR_Value << 8;
if (bSet == 1) {
if(bSet == 1)
{
MSR_Value = SERIAL_MSR_CTS; //flow control, box will inhibit xmit data if CTS line is asserted MSR_Value = SERIAL_MSR_CTS; //flow control, box will inhibit xmit data if CTS line is asserted
} } else {
else
{
MSR_Value = 0; //Box will not inhimbe xmit data due to CTS line MSR_Value = 0; //Box will not inhimbe xmit data due to CTS line
} }
MOUT_Value |= MSR_Value; MOUT_Value |= MSR_Value;
status =
status = usb_control_msg (serial->dev, usb_sndctrlpipe(serial->dev, 0), QT_HW_FLOW_CONTROL_MASK, usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
0x40, MOUT_Value, UartNumber, NULL, 0, 300); QT_HW_FLOW_CONTROL_MASK, 0x40, MOUT_Value,
UartNumber, NULL, 0, 300);
return status; return status;
} }
static int BoxSetSW_FlowCtrl(struct usb_serial *serial, __u16 UartNumber, unsigned char stop_char, unsigned char start_char) static int BoxSetSW_FlowCtrl(struct usb_serial *serial, __u16 UartNumber,
unsigned char stop_char, unsigned char start_char)
{ {
__u16 nSWflowout; __u16 nSWflowout;
int result; int result;
...@@ -2419,8 +2300,10 @@ static int BoxSetSW_FlowCtrl(struct usb_serial *serial, __u16 UartNumber, unsig ...@@ -2419,8 +2300,10 @@ static int BoxSetSW_FlowCtrl(struct usb_serial *serial, __u16 UartNumber, unsig
nSWflowout = start_char << 8; nSWflowout = start_char << 8;
nSWflowout = (unsigned short)stop_char; nSWflowout = (unsigned short)stop_char;
result = usb_control_msg (serial->dev, usb_sndctrlpipe(serial->dev, 0), QT_SW_FLOW_CONTROL_MASK, result =
0x40, nSWflowout, UartNumber, NULL, 0, 300); usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
QT_SW_FLOW_CONTROL_MASK, 0x40, nSWflowout,
UartNumber, NULL, 0, 300);
return result; return result;
} }
...@@ -2428,35 +2311,34 @@ static int BoxDisable_SW_FlowCtrl(struct usb_serial *serial, __u16 UartNumber) ...@@ -2428,35 +2311,34 @@ static int BoxDisable_SW_FlowCtrl(struct usb_serial *serial, __u16 UartNumber)
{ {
int result; int result;
result =
result = usb_control_msg (serial->dev, usb_sndctrlpipe(serial->dev, 0), QT_SW_FLOW_CONTROL_DISABLE, usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
0x40, 0, UartNumber, NULL, 0, 300); QT_SW_FLOW_CONTROL_DISABLE, 0x40, 0, UartNumber,
NULL, 0, 300);
return result; return result;
} }
/***************************************************************************** /*****************************************************************************
* SerialThrottle * SerialThrottle
* this function is called by the tty driver when it wants to stop the data * this function is called by the tty driver when it wants to stop the data
* being read from the port. * being read from the port.
*****************************************************************************/ *****************************************************************************/
static void serial_throttle(struct tty_struct *tty)
static void serial_throttle (struct tty_struct * tty)
{ {
struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data; struct usb_serial_port *port =
struct usb_serial *serial = get_usb_serial (port, __FUNCTION__); (struct usb_serial_port *)tty->driver_data;
struct usb_serial *serial = get_usb_serial(port, __FUNCTION__);
mydbg("%s - port %d\n", __FUNCTION__, port->number); mydbg("%s - port %d\n", __FUNCTION__, port->number);
if (!serial) if (!serial)
return; return;
down (&port->sem); down(&port->sem);
if (!port->open_count) { if (!port->open_count) {
mydbg ("%s - port not open\n", __FUNCTION__); mydbg("%s - port not open\n", __FUNCTION__);
goto exit; goto exit;
} }
//shut down any bulk reads that may be going on //shut down any bulk reads that may be going on
...@@ -2465,64 +2347,63 @@ static void serial_throttle (struct tty_struct * tty) ...@@ -2465,64 +2347,63 @@ static void serial_throttle (struct tty_struct * tty)
port->RxHolding = 1; port->RxHolding = 1;
mydbg("%s - port->RxHolding = 1\n", __FUNCTION__); mydbg("%s - port->RxHolding = 1\n", __FUNCTION__);
exit: exit:
up (&port->sem); up(&port->sem);
return; return;
} }
static void serial_unthrottle (struct tty_struct * tty) static void serial_unthrottle(struct tty_struct *tty)
{ {
struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data; struct usb_serial_port *port =
struct usb_serial *serial = get_usb_serial (port, __FUNCTION__); (struct usb_serial_port *)tty->driver_data;
struct usb_serial *serial = get_usb_serial(port, __FUNCTION__);
unsigned int result; unsigned int result;
if (!serial) if (!serial)
return; return;
down (&port->sem); down(&port->sem);
mydbg("%s - port %d\n", __FUNCTION__, port->number); mydbg("%s - port %d\n", __FUNCTION__, port->number);
if (!port->open_count) { if (!port->open_count) {
mydbg ("%s - port not open\n", __FUNCTION__); mydbg("%s - port not open\n", __FUNCTION__);
goto exit; goto exit;
} }
if(port->RxHolding == 1) if (port->RxHolding == 1) {
{ mydbg("%s -port->RxHolding == 1\n", __FUNCTION__);
mydbg ("%s -port->RxHolding == 1\n", __FUNCTION__);
port->RxHolding = 0; port->RxHolding = 0;
mydbg ("%s - port->RxHolding = 0\n", __FUNCTION__); mydbg("%s - port->RxHolding = 0\n", __FUNCTION__);
/* if we have a bulk endpoint, start it up */ /* if we have a bulk endpoint, start it up */
if ((serial->num_bulk_in) && (port->ReadBulkStopped == 1)) if ((serial->num_bulk_in) && (port->ReadBulkStopped == 1)) {
{
/* Start reading from the device */ /* Start reading from the device */
usb_fill_bulk_urb (port->read_urb, serial->dev, usb_fill_bulk_urb(port->read_urb, serial->dev,
usb_rcvbulkpipe(serial->dev, port->bulk_in_endpointAddress), usb_rcvbulkpipe(serial->dev,
port->
bulk_in_endpointAddress),
port->read_urb->transfer_buffer, port->read_urb->transfer_buffer,
port->read_urb->transfer_buffer_length, port->read_urb->
qt_read_bulk_callback, transfer_buffer_length,
port); qt_read_bulk_callback, port);
result = usb_submit_urb(port->read_urb, GFP_ATOMIC); result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
if (result) if (result)
err("%s - failed restarting read urb, error %d", __FUNCTION__, result); err("%s - failed restarting read urb, error %d",
__FUNCTION__, result);
} }
} }
exit: exit:
up (&port->sem); up(&port->sem);
return; return;
} }
static int serial_break(struct tty_struct *tty, int break_state)
static int serial_break (struct tty_struct *tty, int break_state)
{ {
struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data; struct usb_serial_port *port =
struct usb_serial *serial = get_usb_serial (port, __FUNCTION__); (struct usb_serial_port *)tty->driver_data;
struct usb_serial *serial = get_usb_serial(port, __FUNCTION__);
__u16 UartNumber, Break_Value; __u16 UartNumber, Break_Value;
unsigned int result; unsigned int result;
...@@ -2530,12 +2411,12 @@ static int serial_break (struct tty_struct *tty, int break_state) ...@@ -2530,12 +2411,12 @@ static int serial_break (struct tty_struct *tty, int break_state)
if (!serial) if (!serial)
return -ENODEV; return -ENODEV;
if(break_state == -1) if (break_state == -1)
Break_Value = 1; Break_Value = 1;
else else
Break_Value = 0; Break_Value = 0;
down (&port->sem); down(&port->sem);
mydbg("%s - port %d\n", __FUNCTION__, port->number); mydbg("%s - port %d\n", __FUNCTION__, port->number);
...@@ -2544,18 +2425,18 @@ static int serial_break (struct tty_struct *tty, int break_state) ...@@ -2544,18 +2425,18 @@ static int serial_break (struct tty_struct *tty, int break_state)
goto exit; goto exit;
} }
result = usb_control_msg (serial->dev, usb_sndctrlpipe(serial->dev, 0), QT_BREAK_CONTROL, result =
0x40, Break_Value, UartNumber, NULL, 0, 300); usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
QT_BREAK_CONTROL, 0x40, Break_Value, UartNumber,
NULL, 0, 300);
exit: exit:
up (&port->sem); up(&port->sem);
return 0; return 0;
} }
static int serial_read_proc(char *page, char **start, off_t off, int count,
int *eof, void *data)
static int serial_read_proc (char *page, char **start, off_t off, int count, int *eof, void *data)
{ {
struct usb_serial *serial; struct usb_serial *serial;
int length = 0; int length = 0;
...@@ -2563,21 +2444,26 @@ static int serial_read_proc (char *page, char **start, off_t off, int count, int ...@@ -2563,21 +2444,26 @@ static int serial_read_proc (char *page, char **start, off_t off, int count, int
off_t begin = 0; off_t begin = 0;
mydbg("%s\n", __FUNCTION__); mydbg("%s\n", __FUNCTION__);
length += sprintf (page, "usbserinfo:1.0 driver:%s\n", DRIVER_VERSION); length += sprintf(page, "usbserinfo:1.0 driver:%s\n", DRIVER_VERSION);
for (i = 0; i < SERIAL_TTY_MINORS && length < PAGE_SIZE; ++i) { for (i = 0; i < SERIAL_TTY_MINORS && length < PAGE_SIZE; ++i) {
serial = get_serial_by_minor(i); serial = get_serial_by_minor(i);
if (serial == NULL) if (serial == NULL)
continue; continue;
length += sprintf (page+length, "%d:\n", i); length += sprintf(page + length, "%d:\n", i);
length += sprintf (page+length, " vendor:%04x product:%04x\n", serial->vendor, serial->product); length +=
length += sprintf (page+length, " num_ports:%d\n", serial->num_ports); sprintf(page + length, " vendor:%04x product:%04x\n",
length += sprintf (page+length, " port:%d\n", i - serial->minor + 1); serial->vendor, serial->product);
length +=
sprintf(page + length, " num_ports:%d\n",
serial->num_ports);
length +=
sprintf(page + length, " port:%d\n", i - serial->minor + 1);
// usb_make_path(serial->dev, tmp, sizeof(tmp)); // usb_make_path(serial->dev, tmp, sizeof(tmp));
// length += sprintf (page+length, " path:%s", tmp); // length += sprintf (page+length, " path:%s", tmp);
length += sprintf (page+length, "\n"); length += sprintf(page + length, "\n");
if ((length + begin) > (off + count)) if ((length + begin) > (off + count))
goto done; goto done;
if ((length + begin) < off) { if ((length + begin) < off) {
...@@ -2589,13 +2475,11 @@ static int serial_read_proc (char *page, char **start, off_t off, int count, int ...@@ -2589,13 +2475,11 @@ static int serial_read_proc (char *page, char **start, off_t off, int count, int
done: done:
if (off >= (length + begin)) if (off >= (length + begin))
return 0; return 0;
*start = page + (off-begin); *start = page + (off - begin);
return ((count < begin+length-off) ? count : begin+length-off); return ((count < begin + length - off) ? count : begin + length - off);
} }
int ioctl_serial_usb(struct inode *innod, struct file *filp, unsigned int cmd,
int ioctl_serial_usb (struct inode *innod, struct file *filp, unsigned int cmd,
unsigned long arg) unsigned long arg)
{ {
...@@ -2606,16 +2490,14 @@ int ioctl_serial_usb (struct inode *innod, struct file *filp, unsigned int cmd, ...@@ -2606,16 +2490,14 @@ int ioctl_serial_usb (struct inode *innod, struct file *filp, unsigned int cmd,
struct identity Identity_of; struct identity Identity_of;
struct usb_serial *lastserial, *serial; struct usb_serial *lastserial, *serial;
mydbg(KERN_DEBUG"ioctl_serial_usb cmd =\n"); mydbg(KERN_DEBUG "ioctl_serial_usb cmd =\n");
if (_IOC_TYPE(cmd) != SERIALQT_PCI_IOC_MAGIC) if (_IOC_TYPE(cmd) != SERIALQT_PCI_IOC_MAGIC)
return -ENOTTY; return -ENOTTY;
if (_IOC_NR(cmd) > SERIALQT_IOC_MAXNR) if (_IOC_NR(cmd) > SERIALQT_IOC_MAXNR)
return -ENOTTY; return -ENOTTY;
mydbg(KERN_DEBUG"ioctl_serial_usb cmd = 0x%x\n", cmd); mydbg(KERN_DEBUG "ioctl_serial_usb cmd = 0x%x\n", cmd);
err = 0; err = 0;
switch (cmd) switch (cmd) {
{
case SERIALQT_WRITE_QMCR: case SERIALQT_WRITE_QMCR:
err = -ENOTTY; //initialize as error so if we don't find this one we give//an error. err = -ENOTTY; //initialize as error so if we don't find this one we give//an error.
...@@ -2624,7 +2506,6 @@ int ioctl_serial_usb (struct inode *innod, struct file *filp, unsigned int cmd, ...@@ -2624,7 +2506,6 @@ int ioctl_serial_usb (struct inode *innod, struct file *filp, unsigned int cmd,
ucOPR_NewValue = arg; ucOPR_NewValue = arg;
err = EmulateWriteQMCR_Reg(index, ucOPR_NewValue); err = EmulateWriteQMCR_Reg(index, ucOPR_NewValue);
break; break;
...@@ -2635,11 +2516,8 @@ int ioctl_serial_usb (struct inode *innod, struct file *filp, unsigned int cmd, ...@@ -2635,11 +2516,8 @@ int ioctl_serial_usb (struct inode *innod, struct file *filp, unsigned int cmd,
index = arg >> 16; index = arg >> 16;
counts = 0; counts = 0;
err = EmulateReadQMCR_Reg(index, &uc_Value); err = EmulateReadQMCR_Reg(index, &uc_Value);
if (err == 0) if (err == 0) {
{
err = put_user(uc_Value, p_QMCR_Value); err = put_user(uc_Value, p_QMCR_Value);
} }
break; break;
...@@ -2650,130 +2528,125 @@ int ioctl_serial_usb (struct inode *innod, struct file *filp, unsigned int cmd, ...@@ -2650,130 +2528,125 @@ int ioctl_serial_usb (struct inode *innod, struct file *filp, unsigned int cmd,
//struct usb_serial *lastserial = serial_table[0], *serial; //struct usb_serial *lastserial = serial_table[0], *serial;
lastserial = serial_table[0]; lastserial = serial_table[0];
mydbg(KERN_DEBUG"SERIALQT_GET_NUMOF_UNITS \n"); mydbg(KERN_DEBUG "SERIALQT_GET_NUMOF_UNITS \n");
//if first pointer is nonull, we at least have one box //if first pointer is nonull, we at least have one box
if(lastserial) if (lastserial)
counts = 1; //we at least have one box counts = 1; //we at least have one box
for (index = 1; index < SERIAL_TTY_MINORS ; index++) for (index = 1; index < SERIAL_TTY_MINORS; index++) {
{
serial = serial_table[index]; serial = serial_table[index];
if(serial) if (serial) {
{ if (serial != lastserial) {
if(serial != lastserial)
{
//we had a change in the array, hence another box is there //we had a change in the array, hence another box is there
lastserial = serial; lastserial = serial;
counts++; counts++;
} }
} } else
else
break; break;
} }
mydbg(KERN_DEBUG"ioctl_serial_usb writting counts = %d", counts); mydbg(KERN_DEBUG "ioctl_serial_usb writting counts = %d",
counts);
err = put_user(counts, p_Num_of_adapters); err = put_user(counts, p_Num_of_adapters);
break; break;
case SERIALQT_GET_THIS_UNIT: case SERIALQT_GET_THIS_UNIT:
counts = 0; counts = 0;
p_Identity_of = (struct identity *)arg; p_Identity_of = (struct identity *)arg;
//copy user structure to local variable //copy user structure to local variable
get_user(Identity_of.index, &p_Identity_of->index); get_user(Identity_of.index, &p_Identity_of->index);
mydbg(KERN_DEBUG"SERIALQT_GET_THIS_UNIT Identity_of.index\n"); mydbg(KERN_DEBUG "SERIALQT_GET_THIS_UNIT Identity_of.index\n");
mydbg(KERN_DEBUG"SERIALQT_GET_THIS_UNIT Identity_of.index= 0x%x\n", Identity_of.index); mydbg(KERN_DEBUG
"SERIALQT_GET_THIS_UNIT Identity_of.index= 0x%x\n",
Identity_of.index);
err = -ENOTTY; //initialize as error so if we don't find this one we give err = -ENOTTY; //initialize as error so if we don't find this one we give
//an error. //an error.
serial = find_the_box(Identity_of.index); serial = find_the_box(Identity_of.index);
if(serial) if (serial) {
{ err =
err = put_user(serial->product, &p_Identity_of->n_identity); put_user(serial->product,
&p_Identity_of->n_identity);
} }
break; break;
case SERIALQT_IS422_EXTENDED: case SERIALQT_IS422_EXTENDED:
err = -ENOTTY; //initialize as error so if we don't find this one we give err = -ENOTTY; //initialize as error so if we don't find this one we give
mydbg(KERN_DEBUG"SERIALQT_IS422_EXTENDED \n"); mydbg(KERN_DEBUG "SERIALQT_IS422_EXTENDED \n");
//an error. //an error.
index = arg >> 16; index = arg >> 16;
counts = 0; counts = 0;
mydbg(KERN_DEBUG"SERIALQT_IS422_EXTENDED, looking Identity_of.indext = 0x%x\n",index); mydbg(KERN_DEBUG
"SERIALQT_IS422_EXTENDED, looking Identity_of.indext = 0x%x\n",
index);
serial = find_the_box(index); serial = find_the_box(index);
if(serial) if (serial) {
{ mydbg("%s index = 0x%x, serial = 0x%p\n", __FUNCTION__,
mydbg("%s index = 0x%x, serial = 0x%p\n", __FUNCTION__, index, serial); index, serial);
for (counts = 0; serqt_422_table[counts] != 0; counts++) for (counts = 0; serqt_422_table[counts] != 0; counts++) {
{
mydbg
mydbg("%s serial->product = = 0x%x, serqt_422_table[counts] = 0x%x\n", __FUNCTION__, serial->product, serqt_422_table[counts]); ("%s serial->product = = 0x%x, serqt_422_table[counts] = 0x%x\n",
if(serial->product == serqt_422_table[counts]) __FUNCTION__, serial->product,
{ serqt_422_table[counts]);
if (serial->product == serqt_422_table[counts]) {
err = 0; err = 0;
mydbg("%s found match for 422extended\n", __FUNCTION__); mydbg
("%s found match for 422extended\n",
__FUNCTION__);
break; break;
} }
} }
} }
break; break;
default: default:
err = -ENOTTY; err = -ENOTTY;
} //End switch } //End switch
mydbg("%s returning err = 0x%x\n", __FUNCTION__, err); mydbg("%s returning err = 0x%x\n", __FUNCTION__, err);
return err; return err;
} }
static struct usb_serial *find_the_box(unsigned int index) static struct usb_serial *find_the_box(unsigned int index)
{ {
struct usb_serial *lastserial, *foundserial, *serial; struct usb_serial *lastserial, *foundserial, *serial;
int counts = 0, index2; int counts = 0, index2;
lastserial = serial_table[0]; lastserial = serial_table[0];
foundserial = NULL; foundserial = NULL;
for (index2 = 0; index2 < SERIAL_TTY_MINORS ; index2++) for (index2 = 0; index2 < SERIAL_TTY_MINORS; index2++) {
{
serial = serial_table[index2]; serial = serial_table[index2];
mydbg("%s index = 0x%x, index2 = 0x%x, serial = 0x%p\n", __FUNCTION__, index, index2, serial); mydbg("%s index = 0x%x, index2 = 0x%x, serial = 0x%p\n",
__FUNCTION__, index, index2, serial);
if(serial) if (serial) {
{
//first see if this is the unit we'er looking for //first see if this is the unit we'er looking for
mydbg("%s inside if(serial) counts = 0x%x , index = 0x%x\n", __FUNCTION__, counts, index); mydbg
if(counts == index) ("%s inside if(serial) counts = 0x%x , index = 0x%x\n",
{ __FUNCTION__, counts, index);
if (counts == index) {
//we found the one we're looking for, copythe product Id to user //we found the one we're looking for, copythe product Id to user
mydbg("%s we found the one we're looking for serial = 0x%p\n", __FUNCTION__, serial); mydbg
("%s we found the one we're looking for serial = 0x%p\n",
__FUNCTION__, serial);
foundserial = serial; foundserial = serial;
break; break;
} }
if(serial != lastserial) if (serial != lastserial) {
{
//when we have a change in the pointer //when we have a change in the pointer
lastserial = serial; lastserial = serial;
counts++; counts++;
} }
} } else
else
break; // no matches break; // no matches
} }
...@@ -2781,10 +2654,8 @@ static struct usb_serial *find_the_box(unsigned int index) ...@@ -2781,10 +2654,8 @@ static struct usb_serial *find_the_box(unsigned int index)
return foundserial; return foundserial;
} }
static int EmulateWriteQMCR_Reg(int index, unsigned uc_value)
{
static int EmulateWriteQMCR_Reg(int index, unsigned uc_value)
{
__u16 ATC_Mode = 0; __u16 ATC_Mode = 0;
struct usb_serial *serial; struct usb_serial *serial;
...@@ -2797,18 +2668,16 @@ static struct usb_serial *find_the_box(unsigned int index) ...@@ -2797,18 +2668,16 @@ static struct usb_serial *find_the_box(unsigned int index)
DeviceData.portb = 0; DeviceData.portb = 0;
serial = find_the_box(index); serial = find_the_box(index);
//Determine Duplex mode //Determine Duplex mode
if(!(serial)) if (!(serial))
return -ENOTTY; return -ENOTTY;
status = box_get_device(serial, &DeviceData); status = box_get_device(serial, &DeviceData);
if (status < 0) if (status < 0) {
{ mydbg(__FILE__ "box_set_device failed\n");
mydbg(__FILE__"box_set_device failed\n");
return status; return status;
} }
uc_temp = uc_value & QMCR_HALF_DUPLEX_MASK; uc_temp = uc_value & QMCR_HALF_DUPLEX_MASK;
switch (uc_temp) switch (uc_temp) {
{
case QMCR_FULL_DUPLEX: case QMCR_FULL_DUPLEX:
DeviceData.porta &= ~DUPMODE_BITS; DeviceData.porta &= ~DUPMODE_BITS;
DeviceData.porta |= FULL_DUPLEX; DeviceData.porta |= FULL_DUPLEX;
...@@ -2829,8 +2698,7 @@ static struct usb_serial *find_the_box(unsigned int index) ...@@ -2829,8 +2698,7 @@ static struct usb_serial *find_the_box(unsigned int index)
} }
uc_temp = uc_value & QMCR_CONNECTOR_MASK; uc_temp = uc_value & QMCR_CONNECTOR_MASK;
switch (uc_temp) switch (uc_temp) {
{
case QMCR_MODEM_CONTROL: case QMCR_MODEM_CONTROL:
DeviceData.portb &= ~LOOPMODE_BITS; //reset connection bits DeviceData.portb &= ~LOOPMODE_BITS; //reset connection bits
DeviceData.portb |= MODEM_CTRL; DeviceData.portb |= MODEM_CTRL;
...@@ -2841,42 +2709,39 @@ static struct usb_serial *find_the_box(unsigned int index) ...@@ -2841,42 +2709,39 @@ static struct usb_serial *find_the_box(unsigned int index)
break; break;
} }
mydbg(__FILE__"Calling box_set_device with failed\n"); mydbg(__FILE__ "Calling box_set_device with failed\n");
status = box_set_device(serial, &DeviceData); status = box_set_device(serial, &DeviceData);
if (status < 0) if (status < 0) {
{ mydbg(__FILE__ "box_set_device failed\n");
mydbg(__FILE__"box_set_device failed\n");
return status; return status;
} }
if(uc_value & QMCR_RX_EN_MASK) //This bit (otherwise unused) i'll used to detect whether ATC is selected if (uc_value & QMCR_RX_EN_MASK) //This bit (otherwise unused) i'll used to detect whether ATC is selected
{ {
mydbg(__FILE__"calling BoxsetATC with DeviceData.porta = 0x%x and DeviceData.portb = 0x%x\n", DeviceData.porta, DeviceData.portb); mydbg(__FILE__
"calling BoxsetATC with DeviceData.porta = 0x%x and DeviceData.portb = 0x%x\n",
DeviceData.porta, DeviceData.portb);
status = BoxSetATC(serial, ATC_Mode); status = BoxSetATC(serial, ATC_Mode);
if (status < 0) if (status < 0) {
{ mydbg(__FILE__ "BoxSetATC failed\n");
mydbg(__FILE__"BoxSetATC failed\n");
return status; return status;
} }
} } else {
else
{
mydbg(__FILE__"calling BoxsetATC with DeviceData.porta = 0x%x and DeviceData.portb = 0x%x\n", DeviceData.porta, DeviceData.portb); mydbg(__FILE__
"calling BoxsetATC with DeviceData.porta = 0x%x and DeviceData.portb = 0x%x\n",
DeviceData.porta, DeviceData.portb);
status = BoxSetATC(serial, ATC_DISABLED); status = BoxSetATC(serial, ATC_DISABLED);
if (status < 0) if (status < 0) {
{ mydbg(__FILE__ "BoxSetATC failed\n");
mydbg(__FILE__"BoxSetATC failed\n");
return status; return status;
} }
} }
return 0; return 0;
} }
static int EmulateReadQMCR_Reg(int index, unsigned *uc_value) static int EmulateReadQMCR_Reg(int index, unsigned *uc_value)
{ {
...@@ -2888,18 +2753,16 @@ static int EmulateReadQMCR_Reg(int index, unsigned *uc_value) ...@@ -2888,18 +2753,16 @@ static int EmulateReadQMCR_Reg(int index, unsigned *uc_value)
*uc_value = 0; *uc_value = 0;
serial = find_the_box(index); serial = find_the_box(index);
if(!(serial)) if (!(serial))
return -ENOTTY; return -ENOTTY;
status = box_get_device(serial, &DeviceData); status = box_get_device(serial, &DeviceData);
if (status < 0) if (status < 0) {
{ mydbg(__FILE__ "box_get_device failed\n");
mydbg(__FILE__"box_get_device failed\n");
return status; return status;
} }
uc_temp = DeviceData.porta & DUPMODE_BITS; uc_temp = DeviceData.porta & DUPMODE_BITS;
switch (uc_temp) switch (uc_temp) {
{
case FULL_DUPLEX: case FULL_DUPLEX:
*uc_value |= QMCR_FULL_DUPLEX; *uc_value |= QMCR_FULL_DUPLEX;
break; break;
...@@ -2915,8 +2778,7 @@ static int EmulateReadQMCR_Reg(int index, unsigned *uc_value) ...@@ -2915,8 +2778,7 @@ static int EmulateReadQMCR_Reg(int index, unsigned *uc_value)
uc_temp = DeviceData.portb & LOOPMODE_BITS; //I use this for ATC control se uc_temp = DeviceData.portb & LOOPMODE_BITS; //I use this for ATC control se
switch (uc_temp) switch (uc_temp) {
{
case ALL_LOOPBACK: case ALL_LOOPBACK:
*uc_value |= QMCR_ALL_LOOPBACK; *uc_value |= QMCR_ALL_LOOPBACK;
break; break;
...@@ -2929,8 +2791,7 @@ static int EmulateReadQMCR_Reg(int index, unsigned *uc_value) ...@@ -2929,8 +2791,7 @@ static int EmulateReadQMCR_Reg(int index, unsigned *uc_value)
} }
return 0; return 0;
}
}
static int __init serqt_usb_init(void) static int __init serqt_usb_init(void)
{ {
...@@ -2952,16 +2813,19 @@ static int __init serqt_usb_init(void) ...@@ -2952,16 +2813,19 @@ static int __init serqt_usb_init(void)
/* register this driver with the USB subsystem */ /* register this driver with the USB subsystem */
result = usb_register(&serqt_usb_driver); result = usb_register(&serqt_usb_driver);
if (result < 0) { if (result < 0) {
err("usb_register failed for the "__FILE__" driver. Error number %d", result); err("usb_register failed for the " __FILE__
" driver. Error number %d", result);
return result; return result;
} }
status = 0; // Dynamic assignment of major number status = 0; // Dynamic assignment of major number
major_number = register_chrdev(status, "SerialQT_USB", &serialqt_usb_fops); major_number =
register_chrdev(status, "SerialQT_USB", &serialqt_usb_fops);
if (major_number < 0) { if (major_number < 0) {
mydbg(KERN_DEBUG"No devices found \n\n"); mydbg(KERN_DEBUG "No devices found \n\n");
return -EBUSY; return -EBUSY;
} else } else
mydbg(KERN_DEBUG"SerQT_USB major number assignment = %d \n\n", major_number); mydbg(KERN_DEBUG "SerQT_USB major number assignment = %d \n\n",
major_number);
printk(KERN_INFO DRIVER_DESC " " DRIVER_VERSION); printk(KERN_INFO DRIVER_DESC " " DRIVER_VERSION);
return 0; return 0;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册