xref: /OK3568_Linux_fs/kernel/include/linux/usb/serial.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * USB Serial Converter stuff
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  *	Copyright (C) 1999 - 2012
6*4882a593Smuzhiyun  *	    Greg Kroah-Hartman (greg@kroah.com)
7*4882a593Smuzhiyun  *
8*4882a593Smuzhiyun  *	This program is free software; you can redistribute it and/or modify
9*4882a593Smuzhiyun  *	it under the terms of the GNU General Public License as published by
10*4882a593Smuzhiyun  *	the Free Software Foundation; version 2 of the License.
11*4882a593Smuzhiyun  *
12*4882a593Smuzhiyun  */
13*4882a593Smuzhiyun 
14*4882a593Smuzhiyun #ifndef __LINUX_USB_SERIAL_H
15*4882a593Smuzhiyun #define __LINUX_USB_SERIAL_H
16*4882a593Smuzhiyun 
17*4882a593Smuzhiyun #include <linux/kref.h>
18*4882a593Smuzhiyun #include <linux/mutex.h>
19*4882a593Smuzhiyun #include <linux/serial.h>
20*4882a593Smuzhiyun #include <linux/kfifo.h>
21*4882a593Smuzhiyun 
22*4882a593Smuzhiyun /* The maximum number of ports one device can grab at once */
23*4882a593Smuzhiyun #define MAX_NUM_PORTS		16
24*4882a593Smuzhiyun 
25*4882a593Smuzhiyun /* USB serial flags */
26*4882a593Smuzhiyun #define USB_SERIAL_WRITE_BUSY	0
27*4882a593Smuzhiyun #define USB_SERIAL_THROTTLED	1
28*4882a593Smuzhiyun 
29*4882a593Smuzhiyun /**
30*4882a593Smuzhiyun  * usb_serial_port: structure for the specific ports of a device.
31*4882a593Smuzhiyun  * @serial: pointer back to the struct usb_serial owner of this port.
32*4882a593Smuzhiyun  * @port: pointer to the corresponding tty_port for this port.
33*4882a593Smuzhiyun  * @lock: spinlock to grab when updating portions of this structure.
34*4882a593Smuzhiyun  * @minor: the minor number of the port
35*4882a593Smuzhiyun  * @port_number: the struct usb_serial port number of this port (starts at 0)
36*4882a593Smuzhiyun  * @interrupt_in_buffer: pointer to the interrupt in buffer for this port.
37*4882a593Smuzhiyun  * @interrupt_in_urb: pointer to the interrupt in struct urb for this port.
38*4882a593Smuzhiyun  * @interrupt_in_endpointAddress: endpoint address for the interrupt in pipe
39*4882a593Smuzhiyun  *	for this port.
40*4882a593Smuzhiyun  * @interrupt_out_buffer: pointer to the interrupt out buffer for this port.
41*4882a593Smuzhiyun  * @interrupt_out_size: the size of the interrupt_out_buffer, in bytes.
42*4882a593Smuzhiyun  * @interrupt_out_urb: pointer to the interrupt out struct urb for this port.
43*4882a593Smuzhiyun  * @interrupt_out_endpointAddress: endpoint address for the interrupt out pipe
44*4882a593Smuzhiyun  *	for this port.
45*4882a593Smuzhiyun  * @bulk_in_buffer: pointer to the bulk in buffer for this port.
46*4882a593Smuzhiyun  * @bulk_in_size: the size of the bulk_in_buffer, in bytes.
47*4882a593Smuzhiyun  * @read_urb: pointer to the bulk in struct urb for this port.
48*4882a593Smuzhiyun  * @bulk_in_endpointAddress: endpoint address for the bulk in pipe for this
49*4882a593Smuzhiyun  *	port.
50*4882a593Smuzhiyun  * @bulk_in_buffers: pointers to the bulk in buffers for this port
51*4882a593Smuzhiyun  * @read_urbs: pointers to the bulk in urbs for this port
52*4882a593Smuzhiyun  * @read_urbs_free: status bitmap the for bulk in urbs
53*4882a593Smuzhiyun  * @bulk_out_buffer: pointer to the bulk out buffer for this port.
54*4882a593Smuzhiyun  * @bulk_out_size: the size of the bulk_out_buffer, in bytes.
55*4882a593Smuzhiyun  * @write_urb: pointer to the bulk out struct urb for this port.
56*4882a593Smuzhiyun  * @write_fifo: kfifo used to buffer outgoing data
57*4882a593Smuzhiyun  * @bulk_out_buffers: pointers to the bulk out buffers for this port
58*4882a593Smuzhiyun  * @write_urbs: pointers to the bulk out urbs for this port
59*4882a593Smuzhiyun  * @write_urbs_free: status bitmap the for bulk out urbs
60*4882a593Smuzhiyun  * @icount: interrupt counters
61*4882a593Smuzhiyun  * @tx_bytes: number of bytes currently in host stack queues
62*4882a593Smuzhiyun  * @bulk_out_endpointAddress: endpoint address for the bulk out pipe for this
63*4882a593Smuzhiyun  *	port.
64*4882a593Smuzhiyun  * @flags: usb serial port flags
65*4882a593Smuzhiyun  * @write_wait: a wait_queue_head_t used by the port.
66*4882a593Smuzhiyun  * @work: work queue entry for the line discipline waking up.
67*4882a593Smuzhiyun  * @dev: pointer to the serial device
68*4882a593Smuzhiyun  *
69*4882a593Smuzhiyun  * This structure is used by the usb-serial core and drivers for the specific
70*4882a593Smuzhiyun  * ports of a device.
71*4882a593Smuzhiyun  */
72*4882a593Smuzhiyun struct usb_serial_port {
73*4882a593Smuzhiyun 	struct usb_serial	*serial;
74*4882a593Smuzhiyun 	struct tty_port		port;
75*4882a593Smuzhiyun 	spinlock_t		lock;
76*4882a593Smuzhiyun 	u32			minor;
77*4882a593Smuzhiyun 	u8			port_number;
78*4882a593Smuzhiyun 
79*4882a593Smuzhiyun 	unsigned char		*interrupt_in_buffer;
80*4882a593Smuzhiyun 	struct urb		*interrupt_in_urb;
81*4882a593Smuzhiyun 	__u8			interrupt_in_endpointAddress;
82*4882a593Smuzhiyun 
83*4882a593Smuzhiyun 	unsigned char		*interrupt_out_buffer;
84*4882a593Smuzhiyun 	int			interrupt_out_size;
85*4882a593Smuzhiyun 	struct urb		*interrupt_out_urb;
86*4882a593Smuzhiyun 	__u8			interrupt_out_endpointAddress;
87*4882a593Smuzhiyun 
88*4882a593Smuzhiyun 	unsigned char		*bulk_in_buffer;
89*4882a593Smuzhiyun 	int			bulk_in_size;
90*4882a593Smuzhiyun 	struct urb		*read_urb;
91*4882a593Smuzhiyun 	__u8			bulk_in_endpointAddress;
92*4882a593Smuzhiyun 
93*4882a593Smuzhiyun 	unsigned char		*bulk_in_buffers[2];
94*4882a593Smuzhiyun 	struct urb		*read_urbs[2];
95*4882a593Smuzhiyun 	unsigned long		read_urbs_free;
96*4882a593Smuzhiyun 
97*4882a593Smuzhiyun 	unsigned char		*bulk_out_buffer;
98*4882a593Smuzhiyun 	int			bulk_out_size;
99*4882a593Smuzhiyun 	struct urb		*write_urb;
100*4882a593Smuzhiyun 	struct kfifo		write_fifo;
101*4882a593Smuzhiyun 
102*4882a593Smuzhiyun 	unsigned char		*bulk_out_buffers[2];
103*4882a593Smuzhiyun 	struct urb		*write_urbs[2];
104*4882a593Smuzhiyun 	unsigned long		write_urbs_free;
105*4882a593Smuzhiyun 	__u8			bulk_out_endpointAddress;
106*4882a593Smuzhiyun 
107*4882a593Smuzhiyun 	struct async_icount	icount;
108*4882a593Smuzhiyun 	int			tx_bytes;
109*4882a593Smuzhiyun 
110*4882a593Smuzhiyun 	unsigned long		flags;
111*4882a593Smuzhiyun 	wait_queue_head_t	write_wait;
112*4882a593Smuzhiyun 	struct work_struct	work;
113*4882a593Smuzhiyun 	unsigned long		sysrq; /* sysrq timeout */
114*4882a593Smuzhiyun 	struct device		dev;
115*4882a593Smuzhiyun };
116*4882a593Smuzhiyun #define to_usb_serial_port(d) container_of(d, struct usb_serial_port, dev)
117*4882a593Smuzhiyun 
118*4882a593Smuzhiyun /* get and set the port private data pointer helper functions */
usb_get_serial_port_data(struct usb_serial_port * port)119*4882a593Smuzhiyun static inline void *usb_get_serial_port_data(struct usb_serial_port *port)
120*4882a593Smuzhiyun {
121*4882a593Smuzhiyun 	return dev_get_drvdata(&port->dev);
122*4882a593Smuzhiyun }
123*4882a593Smuzhiyun 
usb_set_serial_port_data(struct usb_serial_port * port,void * data)124*4882a593Smuzhiyun static inline void usb_set_serial_port_data(struct usb_serial_port *port,
125*4882a593Smuzhiyun 					    void *data)
126*4882a593Smuzhiyun {
127*4882a593Smuzhiyun 	dev_set_drvdata(&port->dev, data);
128*4882a593Smuzhiyun }
129*4882a593Smuzhiyun 
130*4882a593Smuzhiyun /**
131*4882a593Smuzhiyun  * usb_serial - structure used by the usb-serial core for a device
132*4882a593Smuzhiyun  * @dev: pointer to the struct usb_device for this device
133*4882a593Smuzhiyun  * @type: pointer to the struct usb_serial_driver for this device
134*4882a593Smuzhiyun  * @interface: pointer to the struct usb_interface for this device
135*4882a593Smuzhiyun  * @num_ports: the number of ports this device has
136*4882a593Smuzhiyun  * @num_interrupt_in: number of interrupt in endpoints we have
137*4882a593Smuzhiyun  * @num_interrupt_out: number of interrupt out endpoints we have
138*4882a593Smuzhiyun  * @num_bulk_in: number of bulk in endpoints we have
139*4882a593Smuzhiyun  * @num_bulk_out: number of bulk out endpoints we have
140*4882a593Smuzhiyun  * @port: array of struct usb_serial_port structures for the different ports.
141*4882a593Smuzhiyun  * @private: place to put any driver specific information that is needed.  The
142*4882a593Smuzhiyun  *	usb-serial driver is required to manage this data, the usb-serial core
143*4882a593Smuzhiyun  *	will not touch this.  Use usb_get_serial_data() and
144*4882a593Smuzhiyun  *	usb_set_serial_data() to access this.
145*4882a593Smuzhiyun  */
146*4882a593Smuzhiyun struct usb_serial {
147*4882a593Smuzhiyun 	struct usb_device		*dev;
148*4882a593Smuzhiyun 	struct usb_serial_driver	*type;
149*4882a593Smuzhiyun 	struct usb_interface		*interface;
150*4882a593Smuzhiyun 	unsigned char			disconnected:1;
151*4882a593Smuzhiyun 	unsigned char			suspending:1;
152*4882a593Smuzhiyun 	unsigned char			attached:1;
153*4882a593Smuzhiyun 	unsigned char			minors_reserved:1;
154*4882a593Smuzhiyun 	unsigned char			num_ports;
155*4882a593Smuzhiyun 	unsigned char			num_port_pointers;
156*4882a593Smuzhiyun 	unsigned char			num_interrupt_in;
157*4882a593Smuzhiyun 	unsigned char			num_interrupt_out;
158*4882a593Smuzhiyun 	unsigned char			num_bulk_in;
159*4882a593Smuzhiyun 	unsigned char			num_bulk_out;
160*4882a593Smuzhiyun 	struct usb_serial_port		*port[MAX_NUM_PORTS];
161*4882a593Smuzhiyun 	struct kref			kref;
162*4882a593Smuzhiyun 	struct mutex			disc_mutex;
163*4882a593Smuzhiyun 	void				*private;
164*4882a593Smuzhiyun };
165*4882a593Smuzhiyun #define to_usb_serial(d) container_of(d, struct usb_serial, kref)
166*4882a593Smuzhiyun 
167*4882a593Smuzhiyun /* get and set the serial private data pointer helper functions */
usb_get_serial_data(struct usb_serial * serial)168*4882a593Smuzhiyun static inline void *usb_get_serial_data(struct usb_serial *serial)
169*4882a593Smuzhiyun {
170*4882a593Smuzhiyun 	return serial->private;
171*4882a593Smuzhiyun }
172*4882a593Smuzhiyun 
usb_set_serial_data(struct usb_serial * serial,void * data)173*4882a593Smuzhiyun static inline void usb_set_serial_data(struct usb_serial *serial, void *data)
174*4882a593Smuzhiyun {
175*4882a593Smuzhiyun 	serial->private = data;
176*4882a593Smuzhiyun }
177*4882a593Smuzhiyun 
178*4882a593Smuzhiyun struct usb_serial_endpoints {
179*4882a593Smuzhiyun 	unsigned char num_bulk_in;
180*4882a593Smuzhiyun 	unsigned char num_bulk_out;
181*4882a593Smuzhiyun 	unsigned char num_interrupt_in;
182*4882a593Smuzhiyun 	unsigned char num_interrupt_out;
183*4882a593Smuzhiyun 	struct usb_endpoint_descriptor *bulk_in[MAX_NUM_PORTS];
184*4882a593Smuzhiyun 	struct usb_endpoint_descriptor *bulk_out[MAX_NUM_PORTS];
185*4882a593Smuzhiyun 	struct usb_endpoint_descriptor *interrupt_in[MAX_NUM_PORTS];
186*4882a593Smuzhiyun 	struct usb_endpoint_descriptor *interrupt_out[MAX_NUM_PORTS];
187*4882a593Smuzhiyun };
188*4882a593Smuzhiyun 
189*4882a593Smuzhiyun /**
190*4882a593Smuzhiyun  * usb_serial_driver - describes a usb serial driver
191*4882a593Smuzhiyun  * @description: pointer to a string that describes this driver.  This string
192*4882a593Smuzhiyun  *	used in the syslog messages when a device is inserted or removed.
193*4882a593Smuzhiyun  * @id_table: pointer to a list of usb_device_id structures that define all
194*4882a593Smuzhiyun  *	of the devices this structure can support.
195*4882a593Smuzhiyun  * @num_ports: the number of different ports this device will have.
196*4882a593Smuzhiyun  * @num_bulk_in: minimum number of bulk-in endpoints
197*4882a593Smuzhiyun  * @num_bulk_out: minimum number of bulk-out endpoints
198*4882a593Smuzhiyun  * @num_interrupt_in: minimum number of interrupt-in endpoints
199*4882a593Smuzhiyun  * @num_interrupt_out: minimum number of interrupt-out endpoints
200*4882a593Smuzhiyun  * @bulk_in_size: minimum number of bytes to allocate for bulk-in buffer
201*4882a593Smuzhiyun  *	(0 = end-point size)
202*4882a593Smuzhiyun  * @bulk_out_size: bytes to allocate for bulk-out buffer (0 = end-point size)
203*4882a593Smuzhiyun  * @calc_num_ports: pointer to a function to determine how many ports this
204*4882a593Smuzhiyun  *	device has dynamically. It can also be used to verify the number of
205*4882a593Smuzhiyun  *	endpoints or to modify the port-endpoint mapping. It will be called
206*4882a593Smuzhiyun  *	after the probe() callback is called, but before attach().
207*4882a593Smuzhiyun  * @probe: pointer to the driver's probe function.
208*4882a593Smuzhiyun  *	This will be called when the device is inserted into the system,
209*4882a593Smuzhiyun  *	but before the device has been fully initialized by the usb_serial
210*4882a593Smuzhiyun  *	subsystem.  Use this function to download any firmware to the device,
211*4882a593Smuzhiyun  *	or any other early initialization that might be needed.
212*4882a593Smuzhiyun  *	Return 0 to continue on with the initialization sequence.  Anything
213*4882a593Smuzhiyun  *	else will abort it.
214*4882a593Smuzhiyun  * @attach: pointer to the driver's attach function.
215*4882a593Smuzhiyun  *	This will be called when the struct usb_serial structure is fully
216*4882a593Smuzhiyun  *	set up.  Do any local initialization of the device, or any private
217*4882a593Smuzhiyun  *	memory structure allocation at this point in time.
218*4882a593Smuzhiyun  * @disconnect: pointer to the driver's disconnect function.  This will be
219*4882a593Smuzhiyun  *	called when the device is unplugged or unbound from the driver.
220*4882a593Smuzhiyun  * @release: pointer to the driver's release function.  This will be called
221*4882a593Smuzhiyun  *	when the usb_serial data structure is about to be destroyed.
222*4882a593Smuzhiyun  * @usb_driver: pointer to the struct usb_driver that controls this
223*4882a593Smuzhiyun  *	device.  This is necessary to allow dynamic ids to be added to
224*4882a593Smuzhiyun  *	the driver from sysfs.
225*4882a593Smuzhiyun  *
226*4882a593Smuzhiyun  * This structure is defines a USB Serial driver.  It provides all of
227*4882a593Smuzhiyun  * the information that the USB serial core code needs.  If the function
228*4882a593Smuzhiyun  * pointers are defined, then the USB serial core code will call them when
229*4882a593Smuzhiyun  * the corresponding tty port functions are called.  If they are not
230*4882a593Smuzhiyun  * called, the generic serial function will be used instead.
231*4882a593Smuzhiyun  *
232*4882a593Smuzhiyun  * The driver.owner field should be set to the module owner of this driver.
233*4882a593Smuzhiyun  * The driver.name field should be set to the name of this driver (remember
234*4882a593Smuzhiyun  * it will show up in sysfs, so it needs to be short and to the point.
235*4882a593Smuzhiyun  * Using the module name is a good idea.)
236*4882a593Smuzhiyun  */
237*4882a593Smuzhiyun struct usb_serial_driver {
238*4882a593Smuzhiyun 	const char *description;
239*4882a593Smuzhiyun 	const struct usb_device_id *id_table;
240*4882a593Smuzhiyun 
241*4882a593Smuzhiyun 	struct list_head	driver_list;
242*4882a593Smuzhiyun 	struct device_driver	driver;
243*4882a593Smuzhiyun 	struct usb_driver	*usb_driver;
244*4882a593Smuzhiyun 	struct usb_dynids	dynids;
245*4882a593Smuzhiyun 
246*4882a593Smuzhiyun 	unsigned char		num_ports;
247*4882a593Smuzhiyun 
248*4882a593Smuzhiyun 	unsigned char		num_bulk_in;
249*4882a593Smuzhiyun 	unsigned char		num_bulk_out;
250*4882a593Smuzhiyun 	unsigned char		num_interrupt_in;
251*4882a593Smuzhiyun 	unsigned char		num_interrupt_out;
252*4882a593Smuzhiyun 
253*4882a593Smuzhiyun 	size_t			bulk_in_size;
254*4882a593Smuzhiyun 	size_t			bulk_out_size;
255*4882a593Smuzhiyun 
256*4882a593Smuzhiyun 	int (*probe)(struct usb_serial *serial, const struct usb_device_id *id);
257*4882a593Smuzhiyun 	int (*attach)(struct usb_serial *serial);
258*4882a593Smuzhiyun 	int (*calc_num_ports)(struct usb_serial *serial,
259*4882a593Smuzhiyun 			struct usb_serial_endpoints *epds);
260*4882a593Smuzhiyun 
261*4882a593Smuzhiyun 	void (*disconnect)(struct usb_serial *serial);
262*4882a593Smuzhiyun 	void (*release)(struct usb_serial *serial);
263*4882a593Smuzhiyun 
264*4882a593Smuzhiyun 	int (*port_probe)(struct usb_serial_port *port);
265*4882a593Smuzhiyun 	int (*port_remove)(struct usb_serial_port *port);
266*4882a593Smuzhiyun 
267*4882a593Smuzhiyun 	int (*suspend)(struct usb_serial *serial, pm_message_t message);
268*4882a593Smuzhiyun 	int (*resume)(struct usb_serial *serial);
269*4882a593Smuzhiyun 	int (*reset_resume)(struct usb_serial *serial);
270*4882a593Smuzhiyun 
271*4882a593Smuzhiyun 	/* serial function calls */
272*4882a593Smuzhiyun 	/* Called by console and by the tty layer */
273*4882a593Smuzhiyun 	int  (*open)(struct tty_struct *tty, struct usb_serial_port *port);
274*4882a593Smuzhiyun 	void (*close)(struct usb_serial_port *port);
275*4882a593Smuzhiyun 	int  (*write)(struct tty_struct *tty, struct usb_serial_port *port,
276*4882a593Smuzhiyun 			const unsigned char *buf, int count);
277*4882a593Smuzhiyun 	/* Called only by the tty layer */
278*4882a593Smuzhiyun 	int  (*write_room)(struct tty_struct *tty);
279*4882a593Smuzhiyun 	int  (*ioctl)(struct tty_struct *tty,
280*4882a593Smuzhiyun 		      unsigned int cmd, unsigned long arg);
281*4882a593Smuzhiyun 	int  (*get_serial)(struct tty_struct *tty, struct serial_struct *ss);
282*4882a593Smuzhiyun 	int  (*set_serial)(struct tty_struct *tty, struct serial_struct *ss);
283*4882a593Smuzhiyun 	void (*set_termios)(struct tty_struct *tty,
284*4882a593Smuzhiyun 			struct usb_serial_port *port, struct ktermios *old);
285*4882a593Smuzhiyun 	void (*break_ctl)(struct tty_struct *tty, int break_state);
286*4882a593Smuzhiyun 	int  (*chars_in_buffer)(struct tty_struct *tty);
287*4882a593Smuzhiyun 	void (*wait_until_sent)(struct tty_struct *tty, long timeout);
288*4882a593Smuzhiyun 	bool (*tx_empty)(struct usb_serial_port *port);
289*4882a593Smuzhiyun 	void (*throttle)(struct tty_struct *tty);
290*4882a593Smuzhiyun 	void (*unthrottle)(struct tty_struct *tty);
291*4882a593Smuzhiyun 	int  (*tiocmget)(struct tty_struct *tty);
292*4882a593Smuzhiyun 	int  (*tiocmset)(struct tty_struct *tty,
293*4882a593Smuzhiyun 			 unsigned int set, unsigned int clear);
294*4882a593Smuzhiyun 	int  (*tiocmiwait)(struct tty_struct *tty, unsigned long arg);
295*4882a593Smuzhiyun 	int  (*get_icount)(struct tty_struct *tty,
296*4882a593Smuzhiyun 			struct serial_icounter_struct *icount);
297*4882a593Smuzhiyun 	/* Called by the tty layer for port level work. There may or may not
298*4882a593Smuzhiyun 	   be an attached tty at this point */
299*4882a593Smuzhiyun 	void (*dtr_rts)(struct usb_serial_port *port, int on);
300*4882a593Smuzhiyun 	int  (*carrier_raised)(struct usb_serial_port *port);
301*4882a593Smuzhiyun 	/* Called by the usb serial hooks to allow the user to rework the
302*4882a593Smuzhiyun 	   termios state */
303*4882a593Smuzhiyun 	void (*init_termios)(struct tty_struct *tty);
304*4882a593Smuzhiyun 	/* USB events */
305*4882a593Smuzhiyun 	void (*read_int_callback)(struct urb *urb);
306*4882a593Smuzhiyun 	void (*write_int_callback)(struct urb *urb);
307*4882a593Smuzhiyun 	void (*read_bulk_callback)(struct urb *urb);
308*4882a593Smuzhiyun 	void (*write_bulk_callback)(struct urb *urb);
309*4882a593Smuzhiyun 	/* Called by the generic read bulk callback */
310*4882a593Smuzhiyun 	void (*process_read_urb)(struct urb *urb);
311*4882a593Smuzhiyun 	/* Called by the generic write implementation */
312*4882a593Smuzhiyun 	int (*prepare_write_buffer)(struct usb_serial_port *port,
313*4882a593Smuzhiyun 						void *dest, size_t size);
314*4882a593Smuzhiyun };
315*4882a593Smuzhiyun #define to_usb_serial_driver(d) \
316*4882a593Smuzhiyun 	container_of(d, struct usb_serial_driver, driver)
317*4882a593Smuzhiyun 
318*4882a593Smuzhiyun int usb_serial_register_drivers(struct usb_serial_driver *const serial_drivers[],
319*4882a593Smuzhiyun 		const char *name, const struct usb_device_id *id_table);
320*4882a593Smuzhiyun void usb_serial_deregister_drivers(struct usb_serial_driver *const serial_drivers[]);
321*4882a593Smuzhiyun void usb_serial_port_softint(struct usb_serial_port *port);
322*4882a593Smuzhiyun 
323*4882a593Smuzhiyun int usb_serial_suspend(struct usb_interface *intf, pm_message_t message);
324*4882a593Smuzhiyun int usb_serial_resume(struct usb_interface *intf);
325*4882a593Smuzhiyun 
326*4882a593Smuzhiyun /* USB Serial console functions */
327*4882a593Smuzhiyun #ifdef CONFIG_USB_SERIAL_CONSOLE
328*4882a593Smuzhiyun void usb_serial_console_init(int minor);
329*4882a593Smuzhiyun void usb_serial_console_exit(void);
330*4882a593Smuzhiyun void usb_serial_console_disconnect(struct usb_serial *serial);
331*4882a593Smuzhiyun #else
usb_serial_console_init(int minor)332*4882a593Smuzhiyun static inline void usb_serial_console_init(int minor) { }
usb_serial_console_exit(void)333*4882a593Smuzhiyun static inline void usb_serial_console_exit(void) { }
usb_serial_console_disconnect(struct usb_serial * serial)334*4882a593Smuzhiyun static inline void usb_serial_console_disconnect(struct usb_serial *serial) {}
335*4882a593Smuzhiyun #endif
336*4882a593Smuzhiyun 
337*4882a593Smuzhiyun /* Functions needed by other parts of the usbserial core */
338*4882a593Smuzhiyun struct usb_serial_port *usb_serial_port_get_by_minor(unsigned int minor);
339*4882a593Smuzhiyun void usb_serial_put(struct usb_serial *serial);
340*4882a593Smuzhiyun int usb_serial_generic_open(struct tty_struct *tty, struct usb_serial_port *port);
341*4882a593Smuzhiyun int usb_serial_generic_write_start(struct usb_serial_port *port, gfp_t mem_flags);
342*4882a593Smuzhiyun int usb_serial_generic_write(struct tty_struct *tty, struct usb_serial_port *port,
343*4882a593Smuzhiyun 		const unsigned char *buf, int count);
344*4882a593Smuzhiyun void usb_serial_generic_close(struct usb_serial_port *port);
345*4882a593Smuzhiyun int usb_serial_generic_resume(struct usb_serial *serial);
346*4882a593Smuzhiyun int usb_serial_generic_write_room(struct tty_struct *tty);
347*4882a593Smuzhiyun int usb_serial_generic_chars_in_buffer(struct tty_struct *tty);
348*4882a593Smuzhiyun void usb_serial_generic_wait_until_sent(struct tty_struct *tty, long timeout);
349*4882a593Smuzhiyun void usb_serial_generic_read_bulk_callback(struct urb *urb);
350*4882a593Smuzhiyun void usb_serial_generic_write_bulk_callback(struct urb *urb);
351*4882a593Smuzhiyun void usb_serial_generic_throttle(struct tty_struct *tty);
352*4882a593Smuzhiyun void usb_serial_generic_unthrottle(struct tty_struct *tty);
353*4882a593Smuzhiyun int usb_serial_generic_tiocmiwait(struct tty_struct *tty, unsigned long arg);
354*4882a593Smuzhiyun int usb_serial_generic_get_icount(struct tty_struct *tty, struct serial_icounter_struct *icount);
355*4882a593Smuzhiyun int usb_serial_generic_register(void);
356*4882a593Smuzhiyun void usb_serial_generic_deregister(void);
357*4882a593Smuzhiyun int usb_serial_generic_submit_read_urbs(struct usb_serial_port *port, gfp_t mem_flags);
358*4882a593Smuzhiyun void usb_serial_generic_process_read_urb(struct urb *urb);
359*4882a593Smuzhiyun int usb_serial_generic_prepare_write_buffer(struct usb_serial_port *port, void *dest, size_t size);
360*4882a593Smuzhiyun 
361*4882a593Smuzhiyun #if defined(CONFIG_USB_SERIAL_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
362*4882a593Smuzhiyun int usb_serial_handle_sysrq_char(struct usb_serial_port *port, unsigned int ch);
363*4882a593Smuzhiyun int usb_serial_handle_break(struct usb_serial_port *port);
364*4882a593Smuzhiyun #else
usb_serial_handle_sysrq_char(struct usb_serial_port * port,unsigned int ch)365*4882a593Smuzhiyun static inline int usb_serial_handle_sysrq_char(struct usb_serial_port *port, unsigned int ch)
366*4882a593Smuzhiyun {
367*4882a593Smuzhiyun 	return 0;
368*4882a593Smuzhiyun }
usb_serial_handle_break(struct usb_serial_port * port)369*4882a593Smuzhiyun static inline int usb_serial_handle_break(struct usb_serial_port *port)
370*4882a593Smuzhiyun {
371*4882a593Smuzhiyun 	return 0;
372*4882a593Smuzhiyun }
373*4882a593Smuzhiyun #endif
374*4882a593Smuzhiyun 
375*4882a593Smuzhiyun void usb_serial_handle_dcd_change(struct usb_serial_port *usb_port,
376*4882a593Smuzhiyun 		struct tty_struct *tty, unsigned int status);
377*4882a593Smuzhiyun 
378*4882a593Smuzhiyun 
379*4882a593Smuzhiyun int usb_serial_bus_register(struct usb_serial_driver *device);
380*4882a593Smuzhiyun void usb_serial_bus_deregister(struct usb_serial_driver *device);
381*4882a593Smuzhiyun 
382*4882a593Smuzhiyun extern struct bus_type usb_serial_bus_type;
383*4882a593Smuzhiyun extern struct tty_driver *usb_serial_tty_driver;
384*4882a593Smuzhiyun 
usb_serial_debug_data(struct device * dev,const char * function,int size,const unsigned char * data)385*4882a593Smuzhiyun static inline void usb_serial_debug_data(struct device *dev,
386*4882a593Smuzhiyun 					 const char *function, int size,
387*4882a593Smuzhiyun 					 const unsigned char *data)
388*4882a593Smuzhiyun {
389*4882a593Smuzhiyun 	dev_dbg(dev, "%s - length = %d, data = %*ph\n",
390*4882a593Smuzhiyun 		function, size, size, data);
391*4882a593Smuzhiyun }
392*4882a593Smuzhiyun 
393*4882a593Smuzhiyun /*
394*4882a593Smuzhiyun  * Macro for reporting errors in write path to avoid inifinite loop
395*4882a593Smuzhiyun  * when port is used as a console.
396*4882a593Smuzhiyun  */
397*4882a593Smuzhiyun #define dev_err_console(usport, fmt, ...)				\
398*4882a593Smuzhiyun do {									\
399*4882a593Smuzhiyun 	static bool __print_once;					\
400*4882a593Smuzhiyun 	struct usb_serial_port *__port = (usport);			\
401*4882a593Smuzhiyun 									\
402*4882a593Smuzhiyun 	if (!__port->port.console || !__print_once) {			\
403*4882a593Smuzhiyun 		__print_once = true;					\
404*4882a593Smuzhiyun 		dev_err(&__port->dev, fmt, ##__VA_ARGS__);		\
405*4882a593Smuzhiyun 	}								\
406*4882a593Smuzhiyun } while (0)
407*4882a593Smuzhiyun 
408*4882a593Smuzhiyun /*
409*4882a593Smuzhiyun  * module_usb_serial_driver() - Helper macro for registering a USB Serial driver
410*4882a593Smuzhiyun  * @__serial_drivers: list of usb_serial drivers to register
411*4882a593Smuzhiyun  * @__ids: all device ids that @__serial_drivers bind to
412*4882a593Smuzhiyun  *
413*4882a593Smuzhiyun  * Helper macro for USB serial drivers which do not do anything special
414*4882a593Smuzhiyun  * in module init/exit. This eliminates a lot of boilerplate. Each
415*4882a593Smuzhiyun  * module may only use this macro once, and calling it replaces
416*4882a593Smuzhiyun  * module_init() and module_exit()
417*4882a593Smuzhiyun  *
418*4882a593Smuzhiyun  */
419*4882a593Smuzhiyun #define usb_serial_module_driver(__name, __serial_drivers, __ids)	\
420*4882a593Smuzhiyun static int __init usb_serial_module_init(void)				\
421*4882a593Smuzhiyun {									\
422*4882a593Smuzhiyun 	return usb_serial_register_drivers(__serial_drivers,		\
423*4882a593Smuzhiyun 					   __name, __ids);		\
424*4882a593Smuzhiyun }									\
425*4882a593Smuzhiyun module_init(usb_serial_module_init);					\
426*4882a593Smuzhiyun static void __exit usb_serial_module_exit(void)				\
427*4882a593Smuzhiyun {									\
428*4882a593Smuzhiyun 	usb_serial_deregister_drivers(__serial_drivers);		\
429*4882a593Smuzhiyun }									\
430*4882a593Smuzhiyun module_exit(usb_serial_module_exit);
431*4882a593Smuzhiyun 
432*4882a593Smuzhiyun #define module_usb_serial_driver(__serial_drivers, __ids)		\
433*4882a593Smuzhiyun 	usb_serial_module_driver(KBUILD_MODNAME, __serial_drivers, __ids)
434*4882a593Smuzhiyun 
435*4882a593Smuzhiyun #endif /* __LINUX_USB_SERIAL_H */
436*4882a593Smuzhiyun 
437