Import 2.4.0-test3pre1
[davej-history.git] / drivers / usb / serial / usb-serial.h
blob430a8fa64781bfea651524cf80fc850b140e3a4d
1 /*
2 * USB Serial Converter driver
4 * Copyright (C) 1999, 2000
5 * Greg Kroah-Hartman (greg@kroah.com)
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * See Documentation/usb/usb-serial.txt for more information on using this driver
17 #ifndef __LINUX_USB_SERIAL_H
18 #define __LINUX_USB_SERIAL_H
20 #include <linux/config.h>
22 #define SERIAL_TTY_MAJOR 188 /* Nice legal number now */
23 #define SERIAL_TTY_MINORS 255 /* loads of devices :) */
25 #define MAX_NUM_PORTS 8 /* The maximum number of ports one device can grab at once */
27 #define USB_SERIAL_MAGIC 0x6702 /* magic number for usb_serial struct */
28 #define USB_SERIAL_PORT_MAGIC 0x7301 /* magic number for usb_serial_port struct */
30 /* parity check flag */
31 #define RELEVANT_IFLAG(iflag) (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK))
34 struct usb_serial_port {
35 int magic;
36 struct usb_serial *serial; /* pointer back to the owner of this port */
37 struct tty_struct * tty; /* the coresponding tty for this port */
38 unsigned char minor;
39 unsigned char number;
40 char active; /* someone has this device open */
42 unsigned char * interrupt_in_buffer;
43 struct urb * interrupt_in_urb;
45 unsigned char * bulk_in_buffer;
46 struct urb * read_urb;
48 unsigned char * bulk_out_buffer;
49 int bulk_out_size;
50 struct urb * write_urb;
52 wait_queue_head_t write_wait;
54 struct tq_struct tqueue; /* task queue for line discipline waking up */
56 void * private; /* data private to the specific port */
59 struct usb_serial {
60 int magic;
61 struct usb_device * dev;
62 struct usb_serial_device_type * type; /* the type of usb serial device this is */
63 struct tty_driver * tty_driver; /* the tty_driver for this device */
64 unsigned char minor; /* the starting minor number for this device */
65 unsigned char num_ports; /* the number of ports this device has */
66 char num_interrupt_in; /* number of interrupt in endpoints we have */
67 char num_bulk_in; /* number of bulk in endpoints we have */
68 char num_bulk_out; /* number of bulk out endpoints we have */
69 struct usb_serial_port port[MAX_NUM_PORTS];
71 void * private; /* data private to the specific driver */
75 #define MUST_HAVE_NOT 0x01
76 #define MUST_HAVE 0x02
77 #define DONT_CARE 0x03
79 #define HAS 0x02
80 #define HAS_NOT 0x01
82 #define NUM_DONT_CARE (-1)
85 /* This structure defines the individual serial converter. */
86 struct usb_serial_device_type {
87 char *name;
88 __u16 *idVendor;
89 __u16 *idProduct;
90 char needs_interrupt_in;
91 char needs_bulk_in;
92 char needs_bulk_out;
93 char num_interrupt_in;
94 char num_bulk_in;
95 char num_bulk_out;
96 char num_ports; /* number of serial ports this device has */
98 /* function call to make before accepting driver */
99 int (*startup) (struct usb_serial *serial); /* return 0 to continue initialization, anything else to abort */
100 void (*shutdown) (struct usb_serial *serial);
102 /* serial function calls */
103 int (*open) (struct usb_serial_port *port, struct file * filp);
104 void (*close) (struct usb_serial_port *port, struct file * filp);
105 int (*write) (struct usb_serial_port *port, int from_user, const unsigned char *buf, int count);
106 int (*write_room) (struct usb_serial_port *port);
107 int (*ioctl) (struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg);
108 void (*set_termios) (struct usb_serial_port *port, struct termios * old);
109 void (*break_ctl) (struct usb_serial_port *port, int break_state);
110 int (*chars_in_buffer) (struct usb_serial_port *port);
111 void (*throttle) (struct usb_serial_port *port);
112 void (*unthrottle) (struct usb_serial_port *port);
114 void (*read_int_callback)(struct urb *urb);
115 void (*read_bulk_callback)(struct urb *urb);
116 void (*write_bulk_callback)(struct urb *urb);
121 extern struct usb_serial_device_type handspring_device;
122 extern struct usb_serial_device_type whiteheat_fake_device;
123 extern struct usb_serial_device_type whiteheat_device;
124 extern struct usb_serial_device_type ftdi_sio_device;
125 extern struct usb_serial_device_type keyspan_pda_fake_device;
126 extern struct usb_serial_device_type keyspan_pda_device;
127 extern struct usb_serial_device_type zyxel_omninet_device;
128 extern struct usb_serial_device_type digi_acceleport_device;
131 /* determine if we should include the EzUSB loader functions */
132 #if defined(CONFIG_USB_SERIAL_KEYSPAN_PDA) || defined(CONFIG_USB_SERIAL_WHITEHEAT)
133 #define USES_EZUSB_FUNCTIONS
134 extern int ezusb_writememory (struct usb_serial *serial, int address, unsigned char *data, int length, __u8 bRequest);
135 extern int ezusb_set_reset (struct usb_serial *serial, unsigned char reset_bit);
136 #else
137 #undef USES_EZUSB_FUNCTIONS
138 #endif
141 /* Inline functions to check the sanity of a pointer that is passed to us */
142 static inline int serial_paranoia_check (struct usb_serial *serial, const char *function)
144 if (!serial) {
145 dbg("%s - serial == NULL", function);
146 return -1;
148 if (serial->magic != USB_SERIAL_MAGIC) {
149 dbg("%s - bad magic number for serial", function);
150 return -1;
152 if (!serial->type) {
153 dbg("%s - serial->type == NULL!", function);
154 return -1;
157 return 0;
161 static inline int port_paranoia_check (struct usb_serial_port *port, const char *function)
163 if (!port) {
164 dbg("%s - port == NULL", function);
165 return -1;
167 if (port->magic != USB_SERIAL_PORT_MAGIC) {
168 dbg("%s - bad magic number for port", function);
169 return -1;
171 if (!port->serial) {
172 dbg("%s - port->serial == NULL", function);
173 return -1;
175 if (!port->tty) {
176 dbg("%s - port->tty == NULL", function);
177 return -1;
180 return 0;
183 #endif /* ifdef __LINUX_USB_SERIAL_H */