xref: /OK3568_Linux_fs/kernel/drivers/usb/serial/qcserial.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * Qualcomm Serial USB driver
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  *	Copyright (c) 2008 QUALCOMM Incorporated.
6*4882a593Smuzhiyun  *	Copyright (c) 2009 Greg Kroah-Hartman <gregkh@suse.de>
7*4882a593Smuzhiyun  *	Copyright (c) 2009 Novell Inc.
8*4882a593Smuzhiyun  */
9*4882a593Smuzhiyun 
10*4882a593Smuzhiyun #include <linux/tty.h>
11*4882a593Smuzhiyun #include <linux/tty_flip.h>
12*4882a593Smuzhiyun #include <linux/module.h>
13*4882a593Smuzhiyun #include <linux/usb.h>
14*4882a593Smuzhiyun #include <linux/usb/serial.h>
15*4882a593Smuzhiyun #include <linux/slab.h>
16*4882a593Smuzhiyun #include "usb-wwan.h"
17*4882a593Smuzhiyun 
18*4882a593Smuzhiyun #define DRIVER_AUTHOR "Qualcomm Inc"
19*4882a593Smuzhiyun #define DRIVER_DESC "Qualcomm USB Serial driver"
20*4882a593Smuzhiyun 
21*4882a593Smuzhiyun #define QUECTEL_EC20_PID	0x9215
22*4882a593Smuzhiyun 
23*4882a593Smuzhiyun /* standard device layouts supported by this driver */
24*4882a593Smuzhiyun enum qcserial_layouts {
25*4882a593Smuzhiyun 	QCSERIAL_G2K = 0,	/* Gobi 2000 */
26*4882a593Smuzhiyun 	QCSERIAL_G1K = 1,	/* Gobi 1000 */
27*4882a593Smuzhiyun 	QCSERIAL_SWI = 2,	/* Sierra Wireless */
28*4882a593Smuzhiyun 	QCSERIAL_HWI = 3,	/* Huawei */
29*4882a593Smuzhiyun };
30*4882a593Smuzhiyun 
31*4882a593Smuzhiyun #define DEVICE_G1K(v, p) \
32*4882a593Smuzhiyun 	USB_DEVICE(v, p), .driver_info = QCSERIAL_G1K
33*4882a593Smuzhiyun #define DEVICE_SWI(v, p) \
34*4882a593Smuzhiyun 	USB_DEVICE(v, p), .driver_info = QCSERIAL_SWI
35*4882a593Smuzhiyun #define DEVICE_HWI(v, p) \
36*4882a593Smuzhiyun 	USB_DEVICE(v, p), .driver_info = QCSERIAL_HWI
37*4882a593Smuzhiyun 
38*4882a593Smuzhiyun static const struct usb_device_id id_table[] = {
39*4882a593Smuzhiyun 	/* Gobi 1000 devices */
40*4882a593Smuzhiyun 	{DEVICE_G1K(0x05c6, 0x9211)},	/* Acer Gobi QDL device */
41*4882a593Smuzhiyun 	{DEVICE_G1K(0x05c6, 0x9212)},	/* Acer Gobi Modem Device */
42*4882a593Smuzhiyun 	{DEVICE_G1K(0x03f0, 0x1f1d)},	/* HP un2400 Gobi Modem Device */
43*4882a593Smuzhiyun 	{DEVICE_G1K(0x03f0, 0x201d)},	/* HP un2400 Gobi QDL Device */
44*4882a593Smuzhiyun 	{DEVICE_G1K(0x04da, 0x250d)},	/* Panasonic Gobi Modem device */
45*4882a593Smuzhiyun 	{DEVICE_G1K(0x04da, 0x250c)},	/* Panasonic Gobi QDL device */
46*4882a593Smuzhiyun 	{DEVICE_G1K(0x413c, 0x8172)},	/* Dell Gobi Modem device */
47*4882a593Smuzhiyun 	{DEVICE_G1K(0x413c, 0x8171)},	/* Dell Gobi QDL device */
48*4882a593Smuzhiyun 	{DEVICE_G1K(0x1410, 0xa001)},	/* Novatel/Verizon USB-1000 */
49*4882a593Smuzhiyun 	{DEVICE_G1K(0x1410, 0xa002)},	/* Novatel Gobi Modem device */
50*4882a593Smuzhiyun 	{DEVICE_G1K(0x1410, 0xa003)},	/* Novatel Gobi Modem device */
51*4882a593Smuzhiyun 	{DEVICE_G1K(0x1410, 0xa004)},	/* Novatel Gobi Modem device */
52*4882a593Smuzhiyun 	{DEVICE_G1K(0x1410, 0xa005)},	/* Novatel Gobi Modem device */
53*4882a593Smuzhiyun 	{DEVICE_G1K(0x1410, 0xa006)},	/* Novatel Gobi Modem device */
54*4882a593Smuzhiyun 	{DEVICE_G1K(0x1410, 0xa007)},	/* Novatel Gobi Modem device */
55*4882a593Smuzhiyun 	{DEVICE_G1K(0x1410, 0xa008)},	/* Novatel Gobi QDL device */
56*4882a593Smuzhiyun 	{DEVICE_G1K(0x0b05, 0x1776)},	/* Asus Gobi Modem device */
57*4882a593Smuzhiyun 	{DEVICE_G1K(0x0b05, 0x1774)},	/* Asus Gobi QDL device */
58*4882a593Smuzhiyun 	{DEVICE_G1K(0x19d2, 0xfff3)},	/* ONDA Gobi Modem device */
59*4882a593Smuzhiyun 	{DEVICE_G1K(0x19d2, 0xfff2)},	/* ONDA Gobi QDL device */
60*4882a593Smuzhiyun 	{DEVICE_G1K(0x1557, 0x0a80)},	/* OQO Gobi QDL device */
61*4882a593Smuzhiyun 	{DEVICE_G1K(0x05c6, 0x9001)},   /* Generic Gobi Modem device */
62*4882a593Smuzhiyun 	{DEVICE_G1K(0x05c6, 0x9002)},	/* Generic Gobi Modem device */
63*4882a593Smuzhiyun 	{DEVICE_G1K(0x05c6, 0x9202)},	/* Generic Gobi Modem device */
64*4882a593Smuzhiyun 	{DEVICE_G1K(0x05c6, 0x9203)},	/* Generic Gobi Modem device */
65*4882a593Smuzhiyun 	{DEVICE_G1K(0x05c6, 0x9222)},	/* Generic Gobi Modem device */
66*4882a593Smuzhiyun 	{DEVICE_G1K(0x05c6, 0x9008)},	/* Generic Gobi QDL device */
67*4882a593Smuzhiyun 	{DEVICE_G1K(0x05c6, 0x9009)},	/* Generic Gobi Modem device */
68*4882a593Smuzhiyun 	{DEVICE_G1K(0x05c6, 0x9201)},	/* Generic Gobi QDL device */
69*4882a593Smuzhiyun 	{DEVICE_G1K(0x05c6, 0x9221)},	/* Generic Gobi QDL device */
70*4882a593Smuzhiyun 	{DEVICE_G1K(0x05c6, 0x9231)},	/* Generic Gobi QDL device */
71*4882a593Smuzhiyun 	{DEVICE_G1K(0x1f45, 0x0001)},	/* Unknown Gobi QDL device */
72*4882a593Smuzhiyun 	{DEVICE_G1K(0x1bc7, 0x900e)},	/* Telit Gobi QDL device */
73*4882a593Smuzhiyun 
74*4882a593Smuzhiyun 	/* Gobi 2000 devices */
75*4882a593Smuzhiyun 	{USB_DEVICE(0x1410, 0xa010)},	/* Novatel Gobi 2000 QDL device */
76*4882a593Smuzhiyun 	{USB_DEVICE(0x1410, 0xa011)},	/* Novatel Gobi 2000 QDL device */
77*4882a593Smuzhiyun 	{USB_DEVICE(0x1410, 0xa012)},	/* Novatel Gobi 2000 QDL device */
78*4882a593Smuzhiyun 	{USB_DEVICE(0x1410, 0xa013)},	/* Novatel Gobi 2000 QDL device */
79*4882a593Smuzhiyun 	{USB_DEVICE(0x1410, 0xa014)},	/* Novatel Gobi 2000 QDL device */
80*4882a593Smuzhiyun 	{USB_DEVICE(0x413c, 0x8185)},	/* Dell Gobi 2000 QDL device (N0218, VU936) */
81*4882a593Smuzhiyun 	{USB_DEVICE(0x413c, 0x8186)},	/* Dell Gobi 2000 Modem device (N0218, VU936) */
82*4882a593Smuzhiyun 	{USB_DEVICE(0x05c6, 0x9208)},	/* Generic Gobi 2000 QDL device */
83*4882a593Smuzhiyun 	{USB_DEVICE(0x05c6, 0x920b)},	/* Generic Gobi 2000 Modem device */
84*4882a593Smuzhiyun 	{USB_DEVICE(0x05c6, 0x9224)},	/* Sony Gobi 2000 QDL device (N0279, VU730) */
85*4882a593Smuzhiyun 	{USB_DEVICE(0x05c6, 0x9225)},	/* Sony Gobi 2000 Modem device (N0279, VU730) */
86*4882a593Smuzhiyun 	{USB_DEVICE(0x05c6, 0x9244)},	/* Samsung Gobi 2000 QDL device (VL176) */
87*4882a593Smuzhiyun 	{USB_DEVICE(0x05c6, 0x9245)},	/* Samsung Gobi 2000 Modem device (VL176) */
88*4882a593Smuzhiyun 	{USB_DEVICE(0x03f0, 0x241d)},	/* HP Gobi 2000 QDL device (VP412) */
89*4882a593Smuzhiyun 	{USB_DEVICE(0x03f0, 0x251d)},	/* HP Gobi 2000 Modem device (VP412) */
90*4882a593Smuzhiyun 	{USB_DEVICE(0x05c6, 0x9214)},	/* Acer Gobi 2000 QDL device (VP413) */
91*4882a593Smuzhiyun 	{USB_DEVICE(0x05c6, 0x9215)},	/* Acer Gobi 2000 Modem device (VP413) */
92*4882a593Smuzhiyun 	{USB_DEVICE(0x05c6, 0x9264)},	/* Asus Gobi 2000 QDL device (VR305) */
93*4882a593Smuzhiyun 	{USB_DEVICE(0x05c6, 0x9265)},	/* Asus Gobi 2000 Modem device (VR305) */
94*4882a593Smuzhiyun 	{USB_DEVICE(0x05c6, 0x9234)},	/* Top Global Gobi 2000 QDL device (VR306) */
95*4882a593Smuzhiyun 	{USB_DEVICE(0x05c6, 0x9235)},	/* Top Global Gobi 2000 Modem device (VR306) */
96*4882a593Smuzhiyun 	{USB_DEVICE(0x05c6, 0x9274)},	/* iRex Technologies Gobi 2000 QDL device (VR307) */
97*4882a593Smuzhiyun 	{USB_DEVICE(0x05c6, 0x9275)},	/* iRex Technologies Gobi 2000 Modem device (VR307) */
98*4882a593Smuzhiyun 	{USB_DEVICE(0x1199, 0x9000)},	/* Sierra Wireless Gobi 2000 QDL device (VT773) */
99*4882a593Smuzhiyun 	{USB_DEVICE(0x1199, 0x9001)},	/* Sierra Wireless Gobi 2000 Modem device (VT773) */
100*4882a593Smuzhiyun 	{USB_DEVICE(0x1199, 0x9002)},	/* Sierra Wireless Gobi 2000 Modem device (VT773) */
101*4882a593Smuzhiyun 	{USB_DEVICE(0x1199, 0x9003)},	/* Sierra Wireless Gobi 2000 Modem device (VT773) */
102*4882a593Smuzhiyun 	{USB_DEVICE(0x1199, 0x9004)},	/* Sierra Wireless Gobi 2000 Modem device (VT773) */
103*4882a593Smuzhiyun 	{USB_DEVICE(0x1199, 0x9005)},	/* Sierra Wireless Gobi 2000 Modem device (VT773) */
104*4882a593Smuzhiyun 	{USB_DEVICE(0x1199, 0x9006)},	/* Sierra Wireless Gobi 2000 Modem device (VT773) */
105*4882a593Smuzhiyun 	{USB_DEVICE(0x1199, 0x9007)},	/* Sierra Wireless Gobi 2000 Modem device (VT773) */
106*4882a593Smuzhiyun 	{USB_DEVICE(0x1199, 0x9008)},	/* Sierra Wireless Gobi 2000 Modem device (VT773) */
107*4882a593Smuzhiyun 	{USB_DEVICE(0x1199, 0x9009)},	/* Sierra Wireless Gobi 2000 Modem device (VT773) */
108*4882a593Smuzhiyun 	{USB_DEVICE(0x1199, 0x900a)},	/* Sierra Wireless Gobi 2000 Modem device (VT773) */
109*4882a593Smuzhiyun 	{USB_DEVICE(0x1199, 0x9011)},   /* Sierra Wireless Gobi 2000 Modem device (MC8305) */
110*4882a593Smuzhiyun 	{USB_DEVICE(0x16d8, 0x8001)},	/* CMDTech Gobi 2000 QDL device (VU922) */
111*4882a593Smuzhiyun 	{USB_DEVICE(0x16d8, 0x8002)},	/* CMDTech Gobi 2000 Modem device (VU922) */
112*4882a593Smuzhiyun 	{USB_DEVICE(0x05c6, 0x9204)},	/* Gobi 2000 QDL device */
113*4882a593Smuzhiyun 	{USB_DEVICE(0x05c6, 0x9205)},	/* Gobi 2000 Modem device */
114*4882a593Smuzhiyun 
115*4882a593Smuzhiyun 	/* Gobi 3000 devices */
116*4882a593Smuzhiyun 	{USB_DEVICE(0x03f0, 0x371d)},	/* HP un2430 Gobi 3000 QDL */
117*4882a593Smuzhiyun 	{USB_DEVICE(0x05c6, 0x920c)},	/* Gobi 3000 QDL */
118*4882a593Smuzhiyun 	{USB_DEVICE(0x05c6, 0x920d)},	/* Gobi 3000 Composite */
119*4882a593Smuzhiyun 	{USB_DEVICE(0x1410, 0xa020)},   /* Novatel Gobi 3000 QDL */
120*4882a593Smuzhiyun 	{USB_DEVICE(0x1410, 0xa021)},	/* Novatel Gobi 3000 Composite */
121*4882a593Smuzhiyun 	{USB_DEVICE(0x413c, 0x8193)},	/* Dell Gobi 3000 QDL */
122*4882a593Smuzhiyun 	{USB_DEVICE(0x413c, 0x8194)},	/* Dell Gobi 3000 Composite */
123*4882a593Smuzhiyun 	{USB_DEVICE(0x413c, 0x81a6)},	/* Dell DW5570 QDL (MC8805) */
124*4882a593Smuzhiyun 	{USB_DEVICE(0x1199, 0x68a4)},	/* Sierra Wireless QDL */
125*4882a593Smuzhiyun 	{USB_DEVICE(0x1199, 0x68a5)},	/* Sierra Wireless Modem */
126*4882a593Smuzhiyun 	{USB_DEVICE(0x1199, 0x68a8)},	/* Sierra Wireless QDL */
127*4882a593Smuzhiyun 	{USB_DEVICE(0x1199, 0x68a9)},	/* Sierra Wireless Modem */
128*4882a593Smuzhiyun 	{USB_DEVICE(0x1199, 0x9010)},	/* Sierra Wireless Gobi 3000 QDL */
129*4882a593Smuzhiyun 	{USB_DEVICE(0x1199, 0x9012)},	/* Sierra Wireless Gobi 3000 QDL */
130*4882a593Smuzhiyun 	{USB_DEVICE(0x1199, 0x9013)},	/* Sierra Wireless Gobi 3000 Modem device (MC8355) */
131*4882a593Smuzhiyun 	{USB_DEVICE(0x1199, 0x9014)},	/* Sierra Wireless Gobi 3000 QDL */
132*4882a593Smuzhiyun 	{USB_DEVICE(0x1199, 0x9015)},	/* Sierra Wireless Gobi 3000 Modem device */
133*4882a593Smuzhiyun 	{USB_DEVICE(0x1199, 0x9018)},	/* Sierra Wireless Gobi 3000 QDL */
134*4882a593Smuzhiyun 	{USB_DEVICE(0x1199, 0x9019)},	/* Sierra Wireless Gobi 3000 Modem device */
135*4882a593Smuzhiyun 	{USB_DEVICE(0x1199, 0x901b)},	/* Sierra Wireless MC7770 */
136*4882a593Smuzhiyun 	{USB_DEVICE(0x12D1, 0x14F0)},	/* Sony Gobi 3000 QDL */
137*4882a593Smuzhiyun 	{USB_DEVICE(0x12D1, 0x14F1)},	/* Sony Gobi 3000 Composite */
138*4882a593Smuzhiyun 	{USB_DEVICE(0x0AF0, 0x8120)},	/* Option GTM681W */
139*4882a593Smuzhiyun 
140*4882a593Smuzhiyun 	/* non-Gobi Sierra Wireless devices */
141*4882a593Smuzhiyun 	{DEVICE_SWI(0x03f0, 0x4e1d)},	/* HP lt4111 LTE/EV-DO/HSPA+ Gobi 4G Module */
142*4882a593Smuzhiyun 	{DEVICE_SWI(0x0f3d, 0x68a2)},	/* Sierra Wireless MC7700 */
143*4882a593Smuzhiyun 	{DEVICE_SWI(0x114f, 0x68a2)},	/* Sierra Wireless MC7750 */
144*4882a593Smuzhiyun 	{DEVICE_SWI(0x1199, 0x68a2)},	/* Sierra Wireless MC7710 */
145*4882a593Smuzhiyun 	{DEVICE_SWI(0x1199, 0x68c0)},	/* Sierra Wireless MC7304/MC7354 */
146*4882a593Smuzhiyun 	{DEVICE_SWI(0x1199, 0x901c)},	/* Sierra Wireless EM7700 */
147*4882a593Smuzhiyun 	{DEVICE_SWI(0x1199, 0x901e)},	/* Sierra Wireless EM7355 QDL */
148*4882a593Smuzhiyun 	{DEVICE_SWI(0x1199, 0x901f)},	/* Sierra Wireless EM7355 */
149*4882a593Smuzhiyun 	{DEVICE_SWI(0x1199, 0x9040)},	/* Sierra Wireless Modem */
150*4882a593Smuzhiyun 	{DEVICE_SWI(0x1199, 0x9041)},	/* Sierra Wireless MC7305/MC7355 */
151*4882a593Smuzhiyun 	{DEVICE_SWI(0x1199, 0x9051)},	/* Netgear AirCard 340U */
152*4882a593Smuzhiyun 	{DEVICE_SWI(0x1199, 0x9053)},	/* Sierra Wireless Modem */
153*4882a593Smuzhiyun 	{DEVICE_SWI(0x1199, 0x9054)},	/* Sierra Wireless Modem */
154*4882a593Smuzhiyun 	{DEVICE_SWI(0x1199, 0x9055)},	/* Netgear AirCard 341U */
155*4882a593Smuzhiyun 	{DEVICE_SWI(0x1199, 0x9056)},	/* Sierra Wireless Modem */
156*4882a593Smuzhiyun 	{DEVICE_SWI(0x1199, 0x9060)},	/* Sierra Wireless Modem */
157*4882a593Smuzhiyun 	{DEVICE_SWI(0x1199, 0x9061)},	/* Sierra Wireless Modem */
158*4882a593Smuzhiyun 	{DEVICE_SWI(0x1199, 0x9062)},	/* Sierra Wireless EM7305 QDL */
159*4882a593Smuzhiyun 	{DEVICE_SWI(0x1199, 0x9063)},	/* Sierra Wireless EM7305 */
160*4882a593Smuzhiyun 	{DEVICE_SWI(0x1199, 0x9070)},	/* Sierra Wireless MC74xx */
161*4882a593Smuzhiyun 	{DEVICE_SWI(0x1199, 0x9071)},	/* Sierra Wireless MC74xx */
162*4882a593Smuzhiyun 	{DEVICE_SWI(0x1199, 0x9078)},	/* Sierra Wireless EM74xx */
163*4882a593Smuzhiyun 	{DEVICE_SWI(0x1199, 0x9079)},	/* Sierra Wireless EM74xx */
164*4882a593Smuzhiyun 	{DEVICE_SWI(0x1199, 0x907a)},	/* Sierra Wireless EM74xx QDL */
165*4882a593Smuzhiyun 	{DEVICE_SWI(0x1199, 0x907b)},	/* Sierra Wireless EM74xx */
166*4882a593Smuzhiyun 	{DEVICE_SWI(0x1199, 0x9090)},	/* Sierra Wireless EM7565 QDL */
167*4882a593Smuzhiyun 	{DEVICE_SWI(0x1199, 0x9091)},	/* Sierra Wireless EM7565 */
168*4882a593Smuzhiyun 	{DEVICE_SWI(0x1199, 0x90d2)},	/* Sierra Wireless EM9191 QDL */
169*4882a593Smuzhiyun 	{DEVICE_SWI(0x1199, 0xc080)},	/* Sierra Wireless EM7590 QDL */
170*4882a593Smuzhiyun 	{DEVICE_SWI(0x1199, 0xc081)},	/* Sierra Wireless EM7590 */
171*4882a593Smuzhiyun 	{DEVICE_SWI(0x413c, 0x81a2)},	/* Dell Wireless 5806 Gobi(TM) 4G LTE Mobile Broadband Card */
172*4882a593Smuzhiyun 	{DEVICE_SWI(0x413c, 0x81a3)},	/* Dell Wireless 5570 HSPA+ (42Mbps) Mobile Broadband Card */
173*4882a593Smuzhiyun 	{DEVICE_SWI(0x413c, 0x81a4)},	/* Dell Wireless 5570e HSPA+ (42Mbps) Mobile Broadband Card */
174*4882a593Smuzhiyun 	{DEVICE_SWI(0x413c, 0x81a8)},	/* Dell Wireless 5808 Gobi(TM) 4G LTE Mobile Broadband Card */
175*4882a593Smuzhiyun 	{DEVICE_SWI(0x413c, 0x81a9)},	/* Dell Wireless 5808e Gobi(TM) 4G LTE Mobile Broadband Card */
176*4882a593Smuzhiyun 	{DEVICE_SWI(0x413c, 0x81b1)},	/* Dell Wireless 5809e Gobi(TM) 4G LTE Mobile Broadband Card */
177*4882a593Smuzhiyun 	{DEVICE_SWI(0x413c, 0x81b3)},	/* Dell Wireless 5809e Gobi(TM) 4G LTE Mobile Broadband Card (rev3) */
178*4882a593Smuzhiyun 	{DEVICE_SWI(0x413c, 0x81b5)},	/* Dell Wireless 5811e QDL */
179*4882a593Smuzhiyun 	{DEVICE_SWI(0x413c, 0x81b6)},	/* Dell Wireless 5811e QDL */
180*4882a593Smuzhiyun 	{DEVICE_SWI(0x413c, 0x81c2)},	/* Dell Wireless 5811e */
181*4882a593Smuzhiyun 	{DEVICE_SWI(0x413c, 0x81cb)},	/* Dell Wireless 5816e QDL */
182*4882a593Smuzhiyun 	{DEVICE_SWI(0x413c, 0x81cc)},	/* Dell Wireless 5816e */
183*4882a593Smuzhiyun 	{DEVICE_SWI(0x413c, 0x81cf)},   /* Dell Wireless 5819 */
184*4882a593Smuzhiyun 	{DEVICE_SWI(0x413c, 0x81d0)},   /* Dell Wireless 5819 */
185*4882a593Smuzhiyun 	{DEVICE_SWI(0x413c, 0x81d1)},   /* Dell Wireless 5818 */
186*4882a593Smuzhiyun 	{DEVICE_SWI(0x413c, 0x81d2)},   /* Dell Wireless 5818 */
187*4882a593Smuzhiyun 
188*4882a593Smuzhiyun 	/* Huawei devices */
189*4882a593Smuzhiyun 	{DEVICE_HWI(0x03f0, 0x581d)},	/* HP lt4112 LTE/HSPA+ Gobi 4G Modem (Huawei me906e) */
190*4882a593Smuzhiyun 
191*4882a593Smuzhiyun 	{ }				/* Terminating entry */
192*4882a593Smuzhiyun };
193*4882a593Smuzhiyun MODULE_DEVICE_TABLE(usb, id_table);
194*4882a593Smuzhiyun 
handle_quectel_ec20(struct device * dev,int ifnum)195*4882a593Smuzhiyun static int handle_quectel_ec20(struct device *dev, int ifnum)
196*4882a593Smuzhiyun {
197*4882a593Smuzhiyun 	int altsetting = 0;
198*4882a593Smuzhiyun 
199*4882a593Smuzhiyun 	/*
200*4882a593Smuzhiyun 	 * Quectel EC20 Mini PCIe LTE module layout:
201*4882a593Smuzhiyun 	 * 0: DM/DIAG (use libqcdm from ModemManager for communication)
202*4882a593Smuzhiyun 	 * 1: NMEA
203*4882a593Smuzhiyun 	 * 2: AT-capable modem port
204*4882a593Smuzhiyun 	 * 3: Modem interface
205*4882a593Smuzhiyun 	 * 4: NDIS
206*4882a593Smuzhiyun 	 */
207*4882a593Smuzhiyun 	switch (ifnum) {
208*4882a593Smuzhiyun 	case 0:
209*4882a593Smuzhiyun 		dev_dbg(dev, "Quectel EC20 DM/DIAG interface found\n");
210*4882a593Smuzhiyun 		break;
211*4882a593Smuzhiyun 	case 1:
212*4882a593Smuzhiyun 		dev_dbg(dev, "Quectel EC20 NMEA GPS interface found\n");
213*4882a593Smuzhiyun 		break;
214*4882a593Smuzhiyun 	case 2:
215*4882a593Smuzhiyun 	case 3:
216*4882a593Smuzhiyun 		dev_dbg(dev, "Quectel EC20 Modem port found\n");
217*4882a593Smuzhiyun 		break;
218*4882a593Smuzhiyun 	case 4:
219*4882a593Smuzhiyun 		/* Don't claim the QMI/net interface */
220*4882a593Smuzhiyun 		altsetting = -1;
221*4882a593Smuzhiyun 		break;
222*4882a593Smuzhiyun 	}
223*4882a593Smuzhiyun 
224*4882a593Smuzhiyun 	return altsetting;
225*4882a593Smuzhiyun }
226*4882a593Smuzhiyun 
qcprobe(struct usb_serial * serial,const struct usb_device_id * id)227*4882a593Smuzhiyun static int qcprobe(struct usb_serial *serial, const struct usb_device_id *id)
228*4882a593Smuzhiyun {
229*4882a593Smuzhiyun 	struct usb_host_interface *intf = serial->interface->cur_altsetting;
230*4882a593Smuzhiyun 	struct device *dev = &serial->dev->dev;
231*4882a593Smuzhiyun 	int retval = -ENODEV;
232*4882a593Smuzhiyun 	__u8 nintf;
233*4882a593Smuzhiyun 	__u8 ifnum;
234*4882a593Smuzhiyun 	int altsetting = -1;
235*4882a593Smuzhiyun 	bool sendsetup = false;
236*4882a593Smuzhiyun 
237*4882a593Smuzhiyun 	/* we only support vendor specific functions */
238*4882a593Smuzhiyun 	if (intf->desc.bInterfaceClass != USB_CLASS_VENDOR_SPEC)
239*4882a593Smuzhiyun 		goto done;
240*4882a593Smuzhiyun 
241*4882a593Smuzhiyun 	nintf = serial->dev->actconfig->desc.bNumInterfaces;
242*4882a593Smuzhiyun 	dev_dbg(dev, "Num Interfaces = %d\n", nintf);
243*4882a593Smuzhiyun 	ifnum = intf->desc.bInterfaceNumber;
244*4882a593Smuzhiyun 	dev_dbg(dev, "This Interface = %d\n", ifnum);
245*4882a593Smuzhiyun 
246*4882a593Smuzhiyun 	if (nintf == 1) {
247*4882a593Smuzhiyun 		/* QDL mode */
248*4882a593Smuzhiyun 		/* Gobi 2000 has a single altsetting, older ones have two */
249*4882a593Smuzhiyun 		if (serial->interface->num_altsetting == 2)
250*4882a593Smuzhiyun 			intf = usb_altnum_to_altsetting(serial->interface, 1);
251*4882a593Smuzhiyun 		else if (serial->interface->num_altsetting > 2)
252*4882a593Smuzhiyun 			goto done;
253*4882a593Smuzhiyun 
254*4882a593Smuzhiyun 		if (intf && intf->desc.bNumEndpoints == 2 &&
255*4882a593Smuzhiyun 		    usb_endpoint_is_bulk_in(&intf->endpoint[0].desc) &&
256*4882a593Smuzhiyun 		    usb_endpoint_is_bulk_out(&intf->endpoint[1].desc)) {
257*4882a593Smuzhiyun 			dev_dbg(dev, "QDL port found\n");
258*4882a593Smuzhiyun 
259*4882a593Smuzhiyun 			if (serial->interface->num_altsetting == 1)
260*4882a593Smuzhiyun 				retval = 0; /* Success */
261*4882a593Smuzhiyun 			else
262*4882a593Smuzhiyun 				altsetting = 1;
263*4882a593Smuzhiyun 		}
264*4882a593Smuzhiyun 		goto done;
265*4882a593Smuzhiyun 
266*4882a593Smuzhiyun 	}
267*4882a593Smuzhiyun 
268*4882a593Smuzhiyun 	/* default to enabling interface */
269*4882a593Smuzhiyun 	altsetting = 0;
270*4882a593Smuzhiyun 
271*4882a593Smuzhiyun 	/*
272*4882a593Smuzhiyun 	 * Composite mode; don't bind to the QMI/net interface as that
273*4882a593Smuzhiyun 	 * gets handled by other drivers.
274*4882a593Smuzhiyun 	 */
275*4882a593Smuzhiyun 
276*4882a593Smuzhiyun 	switch (id->driver_info) {
277*4882a593Smuzhiyun 	case QCSERIAL_G1K:
278*4882a593Smuzhiyun 		/*
279*4882a593Smuzhiyun 		 * Gobi 1K USB layout:
280*4882a593Smuzhiyun 		 * 0: DM/DIAG (use libqcdm from ModemManager for communication)
281*4882a593Smuzhiyun 		 * 1: serial port (doesn't respond)
282*4882a593Smuzhiyun 		 * 2: AT-capable modem port
283*4882a593Smuzhiyun 		 * 3: QMI/net
284*4882a593Smuzhiyun 		 */
285*4882a593Smuzhiyun 		if (nintf < 3 || nintf > 4) {
286*4882a593Smuzhiyun 			dev_err(dev, "unknown number of interfaces: %d\n", nintf);
287*4882a593Smuzhiyun 			altsetting = -1;
288*4882a593Smuzhiyun 			goto done;
289*4882a593Smuzhiyun 		}
290*4882a593Smuzhiyun 
291*4882a593Smuzhiyun 		if (ifnum == 0) {
292*4882a593Smuzhiyun 			dev_dbg(dev, "Gobi 1K DM/DIAG interface found\n");
293*4882a593Smuzhiyun 			altsetting = 1;
294*4882a593Smuzhiyun 		} else if (ifnum == 2)
295*4882a593Smuzhiyun 			dev_dbg(dev, "Modem port found\n");
296*4882a593Smuzhiyun 		else
297*4882a593Smuzhiyun 			altsetting = -1;
298*4882a593Smuzhiyun 		break;
299*4882a593Smuzhiyun 	case QCSERIAL_G2K:
300*4882a593Smuzhiyun 		/* handle non-standard layouts */
301*4882a593Smuzhiyun 		if (nintf == 5 && id->idProduct == QUECTEL_EC20_PID) {
302*4882a593Smuzhiyun 			altsetting = handle_quectel_ec20(dev, ifnum);
303*4882a593Smuzhiyun 			goto done;
304*4882a593Smuzhiyun 		}
305*4882a593Smuzhiyun 
306*4882a593Smuzhiyun 		/*
307*4882a593Smuzhiyun 		 * Gobi 2K+ USB layout:
308*4882a593Smuzhiyun 		 * 0: QMI/net
309*4882a593Smuzhiyun 		 * 1: DM/DIAG (use libqcdm from ModemManager for communication)
310*4882a593Smuzhiyun 		 * 2: AT-capable modem port
311*4882a593Smuzhiyun 		 * 3: NMEA
312*4882a593Smuzhiyun 		 */
313*4882a593Smuzhiyun 		if (nintf < 3 || nintf > 4) {
314*4882a593Smuzhiyun 			dev_err(dev, "unknown number of interfaces: %d\n", nintf);
315*4882a593Smuzhiyun 			altsetting = -1;
316*4882a593Smuzhiyun 			goto done;
317*4882a593Smuzhiyun 		}
318*4882a593Smuzhiyun 
319*4882a593Smuzhiyun 		switch (ifnum) {
320*4882a593Smuzhiyun 		case 0:
321*4882a593Smuzhiyun 			/* Don't claim the QMI/net interface */
322*4882a593Smuzhiyun 			altsetting = -1;
323*4882a593Smuzhiyun 			break;
324*4882a593Smuzhiyun 		case 1:
325*4882a593Smuzhiyun 			dev_dbg(dev, "Gobi 2K+ DM/DIAG interface found\n");
326*4882a593Smuzhiyun 			break;
327*4882a593Smuzhiyun 		case 2:
328*4882a593Smuzhiyun 			dev_dbg(dev, "Modem port found\n");
329*4882a593Smuzhiyun 			break;
330*4882a593Smuzhiyun 		case 3:
331*4882a593Smuzhiyun 			/*
332*4882a593Smuzhiyun 			 * NMEA (serial line 9600 8N1)
333*4882a593Smuzhiyun 			 * # echo "\$GPS_START" > /dev/ttyUSBx
334*4882a593Smuzhiyun 			 * # echo "\$GPS_STOP"  > /dev/ttyUSBx
335*4882a593Smuzhiyun 			 */
336*4882a593Smuzhiyun 			dev_dbg(dev, "Gobi 2K+ NMEA GPS interface found\n");
337*4882a593Smuzhiyun 			break;
338*4882a593Smuzhiyun 		}
339*4882a593Smuzhiyun 		break;
340*4882a593Smuzhiyun 	case QCSERIAL_SWI:
341*4882a593Smuzhiyun 		/*
342*4882a593Smuzhiyun 		 * Sierra Wireless layout:
343*4882a593Smuzhiyun 		 * 0: DM/DIAG (use libqcdm from ModemManager for communication)
344*4882a593Smuzhiyun 		 * 2: NMEA
345*4882a593Smuzhiyun 		 * 3: AT-capable modem port
346*4882a593Smuzhiyun 		 * 8: QMI/net
347*4882a593Smuzhiyun 		 */
348*4882a593Smuzhiyun 		switch (ifnum) {
349*4882a593Smuzhiyun 		case 0:
350*4882a593Smuzhiyun 			dev_dbg(dev, "DM/DIAG interface found\n");
351*4882a593Smuzhiyun 			break;
352*4882a593Smuzhiyun 		case 2:
353*4882a593Smuzhiyun 			dev_dbg(dev, "NMEA GPS interface found\n");
354*4882a593Smuzhiyun 			sendsetup = true;
355*4882a593Smuzhiyun 			break;
356*4882a593Smuzhiyun 		case 3:
357*4882a593Smuzhiyun 			dev_dbg(dev, "Modem port found\n");
358*4882a593Smuzhiyun 			sendsetup = true;
359*4882a593Smuzhiyun 			break;
360*4882a593Smuzhiyun 		default:
361*4882a593Smuzhiyun 			/* don't claim any unsupported interface */
362*4882a593Smuzhiyun 			altsetting = -1;
363*4882a593Smuzhiyun 			break;
364*4882a593Smuzhiyun 		}
365*4882a593Smuzhiyun 		break;
366*4882a593Smuzhiyun 	case QCSERIAL_HWI:
367*4882a593Smuzhiyun 		/*
368*4882a593Smuzhiyun 		 * Huawei devices map functions by subclass + protocol
369*4882a593Smuzhiyun 		 * instead of interface numbers. The protocol identify
370*4882a593Smuzhiyun 		 * a specific function, while the subclass indicate a
371*4882a593Smuzhiyun 		 * specific firmware source
372*4882a593Smuzhiyun 		 *
373*4882a593Smuzhiyun 		 * This is a list of functions known to be non-serial.  The rest
374*4882a593Smuzhiyun 		 * are assumed to be serial and will be handled by this driver
375*4882a593Smuzhiyun 		 */
376*4882a593Smuzhiyun 		switch (intf->desc.bInterfaceProtocol) {
377*4882a593Smuzhiyun 			/* QMI combined (qmi_wwan) */
378*4882a593Smuzhiyun 		case 0x07:
379*4882a593Smuzhiyun 		case 0x37:
380*4882a593Smuzhiyun 		case 0x67:
381*4882a593Smuzhiyun 			/* QMI data (qmi_wwan) */
382*4882a593Smuzhiyun 		case 0x08:
383*4882a593Smuzhiyun 		case 0x38:
384*4882a593Smuzhiyun 		case 0x68:
385*4882a593Smuzhiyun 			/* QMI control (qmi_wwan) */
386*4882a593Smuzhiyun 		case 0x09:
387*4882a593Smuzhiyun 		case 0x39:
388*4882a593Smuzhiyun 		case 0x69:
389*4882a593Smuzhiyun 			/* NCM like (huawei_cdc_ncm) */
390*4882a593Smuzhiyun 		case 0x16:
391*4882a593Smuzhiyun 		case 0x46:
392*4882a593Smuzhiyun 		case 0x76:
393*4882a593Smuzhiyun 			altsetting = -1;
394*4882a593Smuzhiyun 			break;
395*4882a593Smuzhiyun 		default:
396*4882a593Smuzhiyun 			dev_dbg(dev, "Huawei type serial port found (%02x/%02x/%02x)\n",
397*4882a593Smuzhiyun 				intf->desc.bInterfaceClass,
398*4882a593Smuzhiyun 				intf->desc.bInterfaceSubClass,
399*4882a593Smuzhiyun 				intf->desc.bInterfaceProtocol);
400*4882a593Smuzhiyun 		}
401*4882a593Smuzhiyun 		break;
402*4882a593Smuzhiyun 	default:
403*4882a593Smuzhiyun 		dev_err(dev, "unsupported device layout type: %lu\n",
404*4882a593Smuzhiyun 			id->driver_info);
405*4882a593Smuzhiyun 		break;
406*4882a593Smuzhiyun 	}
407*4882a593Smuzhiyun 
408*4882a593Smuzhiyun done:
409*4882a593Smuzhiyun 	if (altsetting >= 0) {
410*4882a593Smuzhiyun 		retval = usb_set_interface(serial->dev, ifnum, altsetting);
411*4882a593Smuzhiyun 		if (retval < 0) {
412*4882a593Smuzhiyun 			dev_err(dev,
413*4882a593Smuzhiyun 				"Could not set interface, error %d\n",
414*4882a593Smuzhiyun 				retval);
415*4882a593Smuzhiyun 			retval = -ENODEV;
416*4882a593Smuzhiyun 		}
417*4882a593Smuzhiyun 	}
418*4882a593Smuzhiyun 
419*4882a593Smuzhiyun 	if (!retval)
420*4882a593Smuzhiyun 		usb_set_serial_data(serial, (void *)(unsigned long)sendsetup);
421*4882a593Smuzhiyun 
422*4882a593Smuzhiyun 	return retval;
423*4882a593Smuzhiyun }
424*4882a593Smuzhiyun 
qc_attach(struct usb_serial * serial)425*4882a593Smuzhiyun static int qc_attach(struct usb_serial *serial)
426*4882a593Smuzhiyun {
427*4882a593Smuzhiyun 	struct usb_wwan_intf_private *data;
428*4882a593Smuzhiyun 	bool sendsetup;
429*4882a593Smuzhiyun 
430*4882a593Smuzhiyun 	data = kzalloc(sizeof(*data), GFP_KERNEL);
431*4882a593Smuzhiyun 	if (!data)
432*4882a593Smuzhiyun 		return -ENOMEM;
433*4882a593Smuzhiyun 
434*4882a593Smuzhiyun 	sendsetup = !!(unsigned long)(usb_get_serial_data(serial));
435*4882a593Smuzhiyun 	if (sendsetup)
436*4882a593Smuzhiyun 		data->use_send_setup = 1;
437*4882a593Smuzhiyun 
438*4882a593Smuzhiyun 	spin_lock_init(&data->susp_lock);
439*4882a593Smuzhiyun 
440*4882a593Smuzhiyun 	usb_set_serial_data(serial, data);
441*4882a593Smuzhiyun 
442*4882a593Smuzhiyun 	return 0;
443*4882a593Smuzhiyun }
444*4882a593Smuzhiyun 
qc_release(struct usb_serial * serial)445*4882a593Smuzhiyun static void qc_release(struct usb_serial *serial)
446*4882a593Smuzhiyun {
447*4882a593Smuzhiyun 	struct usb_wwan_intf_private *priv = usb_get_serial_data(serial);
448*4882a593Smuzhiyun 
449*4882a593Smuzhiyun 	usb_set_serial_data(serial, NULL);
450*4882a593Smuzhiyun 	kfree(priv);
451*4882a593Smuzhiyun }
452*4882a593Smuzhiyun 
453*4882a593Smuzhiyun static struct usb_serial_driver qcdevice = {
454*4882a593Smuzhiyun 	.driver = {
455*4882a593Smuzhiyun 		.owner     = THIS_MODULE,
456*4882a593Smuzhiyun 		.name      = "qcserial",
457*4882a593Smuzhiyun 	},
458*4882a593Smuzhiyun 	.description         = "Qualcomm USB modem",
459*4882a593Smuzhiyun 	.id_table            = id_table,
460*4882a593Smuzhiyun 	.num_ports           = 1,
461*4882a593Smuzhiyun 	.probe               = qcprobe,
462*4882a593Smuzhiyun 	.open		     = usb_wwan_open,
463*4882a593Smuzhiyun 	.close		     = usb_wwan_close,
464*4882a593Smuzhiyun 	.dtr_rts	     = usb_wwan_dtr_rts,
465*4882a593Smuzhiyun 	.write		     = usb_wwan_write,
466*4882a593Smuzhiyun 	.write_room	     = usb_wwan_write_room,
467*4882a593Smuzhiyun 	.chars_in_buffer     = usb_wwan_chars_in_buffer,
468*4882a593Smuzhiyun 	.tiocmget            = usb_wwan_tiocmget,
469*4882a593Smuzhiyun 	.tiocmset            = usb_wwan_tiocmset,
470*4882a593Smuzhiyun 	.attach              = qc_attach,
471*4882a593Smuzhiyun 	.release	     = qc_release,
472*4882a593Smuzhiyun 	.port_probe          = usb_wwan_port_probe,
473*4882a593Smuzhiyun 	.port_remove	     = usb_wwan_port_remove,
474*4882a593Smuzhiyun #ifdef CONFIG_PM
475*4882a593Smuzhiyun 	.suspend	     = usb_wwan_suspend,
476*4882a593Smuzhiyun 	.resume		     = usb_wwan_resume,
477*4882a593Smuzhiyun #endif
478*4882a593Smuzhiyun };
479*4882a593Smuzhiyun 
480*4882a593Smuzhiyun static struct usb_serial_driver * const serial_drivers[] = {
481*4882a593Smuzhiyun 	&qcdevice, NULL
482*4882a593Smuzhiyun };
483*4882a593Smuzhiyun 
484*4882a593Smuzhiyun module_usb_serial_driver(serial_drivers, id_table);
485*4882a593Smuzhiyun 
486*4882a593Smuzhiyun MODULE_AUTHOR(DRIVER_AUTHOR);
487*4882a593Smuzhiyun MODULE_DESCRIPTION(DRIVER_DESC);
488*4882a593Smuzhiyun MODULE_LICENSE("GPL v2");
489