162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Qualcomm Serial USB driver
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci *	Copyright (c) 2008 QUALCOMM Incorporated.
662306a36Sopenharmony_ci *	Copyright (c) 2009 Greg Kroah-Hartman <gregkh@suse.de>
762306a36Sopenharmony_ci *	Copyright (c) 2009 Novell Inc.
862306a36Sopenharmony_ci */
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci#include <linux/tty.h>
1162306a36Sopenharmony_ci#include <linux/tty_flip.h>
1262306a36Sopenharmony_ci#include <linux/module.h>
1362306a36Sopenharmony_ci#include <linux/usb.h>
1462306a36Sopenharmony_ci#include <linux/usb/serial.h>
1562306a36Sopenharmony_ci#include <linux/slab.h>
1662306a36Sopenharmony_ci#include "usb-wwan.h"
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_ci#define DRIVER_AUTHOR "Qualcomm Inc"
1962306a36Sopenharmony_ci#define DRIVER_DESC "Qualcomm USB Serial driver"
2062306a36Sopenharmony_ci
2162306a36Sopenharmony_ci#define QUECTEL_EC20_PID	0x9215
2262306a36Sopenharmony_ci
2362306a36Sopenharmony_ci/* standard device layouts supported by this driver */
2462306a36Sopenharmony_cienum qcserial_layouts {
2562306a36Sopenharmony_ci	QCSERIAL_G2K = 0,	/* Gobi 2000 */
2662306a36Sopenharmony_ci	QCSERIAL_G1K = 1,	/* Gobi 1000 */
2762306a36Sopenharmony_ci	QCSERIAL_SWI = 2,	/* Sierra Wireless */
2862306a36Sopenharmony_ci	QCSERIAL_HWI = 3,	/* Huawei */
2962306a36Sopenharmony_ci};
3062306a36Sopenharmony_ci
3162306a36Sopenharmony_ci#define DEVICE_G1K(v, p) \
3262306a36Sopenharmony_ci	USB_DEVICE(v, p), .driver_info = QCSERIAL_G1K
3362306a36Sopenharmony_ci#define DEVICE_SWI(v, p) \
3462306a36Sopenharmony_ci	USB_DEVICE(v, p), .driver_info = QCSERIAL_SWI
3562306a36Sopenharmony_ci#define DEVICE_HWI(v, p) \
3662306a36Sopenharmony_ci	USB_DEVICE(v, p), .driver_info = QCSERIAL_HWI
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_cistatic const struct usb_device_id id_table[] = {
3962306a36Sopenharmony_ci	/* Gobi 1000 devices */
4062306a36Sopenharmony_ci	{DEVICE_G1K(0x05c6, 0x9211)},	/* Acer Gobi QDL device */
4162306a36Sopenharmony_ci	{DEVICE_G1K(0x05c6, 0x9212)},	/* Acer Gobi Modem Device */
4262306a36Sopenharmony_ci	{DEVICE_G1K(0x03f0, 0x1f1d)},	/* HP un2400 Gobi Modem Device */
4362306a36Sopenharmony_ci	{DEVICE_G1K(0x03f0, 0x201d)},	/* HP un2400 Gobi QDL Device */
4462306a36Sopenharmony_ci	{DEVICE_G1K(0x04da, 0x250d)},	/* Panasonic Gobi Modem device */
4562306a36Sopenharmony_ci	{DEVICE_G1K(0x04da, 0x250c)},	/* Panasonic Gobi QDL device */
4662306a36Sopenharmony_ci	{DEVICE_G1K(0x413c, 0x8172)},	/* Dell Gobi Modem device */
4762306a36Sopenharmony_ci	{DEVICE_G1K(0x413c, 0x8171)},	/* Dell Gobi QDL device */
4862306a36Sopenharmony_ci	{DEVICE_G1K(0x1410, 0xa001)},	/* Novatel/Verizon USB-1000 */
4962306a36Sopenharmony_ci	{DEVICE_G1K(0x1410, 0xa002)},	/* Novatel Gobi Modem device */
5062306a36Sopenharmony_ci	{DEVICE_G1K(0x1410, 0xa003)},	/* Novatel Gobi Modem device */
5162306a36Sopenharmony_ci	{DEVICE_G1K(0x1410, 0xa004)},	/* Novatel Gobi Modem device */
5262306a36Sopenharmony_ci	{DEVICE_G1K(0x1410, 0xa005)},	/* Novatel Gobi Modem device */
5362306a36Sopenharmony_ci	{DEVICE_G1K(0x1410, 0xa006)},	/* Novatel Gobi Modem device */
5462306a36Sopenharmony_ci	{DEVICE_G1K(0x1410, 0xa007)},	/* Novatel Gobi Modem device */
5562306a36Sopenharmony_ci	{DEVICE_G1K(0x1410, 0xa008)},	/* Novatel Gobi QDL device */
5662306a36Sopenharmony_ci	{DEVICE_G1K(0x0b05, 0x1776)},	/* Asus Gobi Modem device */
5762306a36Sopenharmony_ci	{DEVICE_G1K(0x0b05, 0x1774)},	/* Asus Gobi QDL device */
5862306a36Sopenharmony_ci	{DEVICE_G1K(0x19d2, 0xfff3)},	/* ONDA Gobi Modem device */
5962306a36Sopenharmony_ci	{DEVICE_G1K(0x19d2, 0xfff2)},	/* ONDA Gobi QDL device */
6062306a36Sopenharmony_ci	{DEVICE_G1K(0x1557, 0x0a80)},	/* OQO Gobi QDL device */
6162306a36Sopenharmony_ci	{DEVICE_G1K(0x05c6, 0x9001)},   /* Generic Gobi Modem device */
6262306a36Sopenharmony_ci	{DEVICE_G1K(0x05c6, 0x9002)},	/* Generic Gobi Modem device */
6362306a36Sopenharmony_ci	{DEVICE_G1K(0x05c6, 0x9202)},	/* Generic Gobi Modem device */
6462306a36Sopenharmony_ci	{DEVICE_G1K(0x05c6, 0x9203)},	/* Generic Gobi Modem device */
6562306a36Sopenharmony_ci	{DEVICE_G1K(0x05c6, 0x9222)},	/* Generic Gobi Modem device */
6662306a36Sopenharmony_ci	{DEVICE_G1K(0x05c6, 0x9008)},	/* Generic Gobi QDL device */
6762306a36Sopenharmony_ci	{DEVICE_G1K(0x05c6, 0x9009)},	/* Generic Gobi Modem device */
6862306a36Sopenharmony_ci	{DEVICE_G1K(0x05c6, 0x9201)},	/* Generic Gobi QDL device */
6962306a36Sopenharmony_ci	{DEVICE_G1K(0x05c6, 0x9221)},	/* Generic Gobi QDL device */
7062306a36Sopenharmony_ci	{DEVICE_G1K(0x05c6, 0x9231)},	/* Generic Gobi QDL device */
7162306a36Sopenharmony_ci	{DEVICE_G1K(0x1f45, 0x0001)},	/* Unknown Gobi QDL device */
7262306a36Sopenharmony_ci	{DEVICE_G1K(0x1bc7, 0x900e)},	/* Telit Gobi QDL device */
7362306a36Sopenharmony_ci
7462306a36Sopenharmony_ci	/* Gobi 2000 devices */
7562306a36Sopenharmony_ci	{USB_DEVICE(0x1410, 0xa010)},	/* Novatel Gobi 2000 QDL device */
7662306a36Sopenharmony_ci	{USB_DEVICE(0x1410, 0xa011)},	/* Novatel Gobi 2000 QDL device */
7762306a36Sopenharmony_ci	{USB_DEVICE(0x1410, 0xa012)},	/* Novatel Gobi 2000 QDL device */
7862306a36Sopenharmony_ci	{USB_DEVICE(0x1410, 0xa013)},	/* Novatel Gobi 2000 QDL device */
7962306a36Sopenharmony_ci	{USB_DEVICE(0x1410, 0xa014)},	/* Novatel Gobi 2000 QDL device */
8062306a36Sopenharmony_ci	{USB_DEVICE(0x413c, 0x8185)},	/* Dell Gobi 2000 QDL device (N0218, VU936) */
8162306a36Sopenharmony_ci	{USB_DEVICE(0x413c, 0x8186)},	/* Dell Gobi 2000 Modem device (N0218, VU936) */
8262306a36Sopenharmony_ci	{USB_DEVICE(0x05c6, 0x9208)},	/* Generic Gobi 2000 QDL device */
8362306a36Sopenharmony_ci	{USB_DEVICE(0x05c6, 0x920b)},	/* Generic Gobi 2000 Modem device */
8462306a36Sopenharmony_ci	{USB_DEVICE(0x05c6, 0x9224)},	/* Sony Gobi 2000 QDL device (N0279, VU730) */
8562306a36Sopenharmony_ci	{USB_DEVICE(0x05c6, 0x9225)},	/* Sony Gobi 2000 Modem device (N0279, VU730) */
8662306a36Sopenharmony_ci	{USB_DEVICE(0x05c6, 0x9244)},	/* Samsung Gobi 2000 QDL device (VL176) */
8762306a36Sopenharmony_ci	{USB_DEVICE(0x05c6, 0x9245)},	/* Samsung Gobi 2000 Modem device (VL176) */
8862306a36Sopenharmony_ci	{USB_DEVICE(0x03f0, 0x241d)},	/* HP Gobi 2000 QDL device (VP412) */
8962306a36Sopenharmony_ci	{USB_DEVICE(0x03f0, 0x251d)},	/* HP Gobi 2000 Modem device (VP412) */
9062306a36Sopenharmony_ci	{USB_DEVICE(0x05c6, 0x9214)},	/* Acer Gobi 2000 QDL device (VP413) */
9162306a36Sopenharmony_ci	{USB_DEVICE(0x05c6, 0x9215)},	/* Acer Gobi 2000 Modem device (VP413) */
9262306a36Sopenharmony_ci	{USB_DEVICE(0x05c6, 0x9264)},	/* Asus Gobi 2000 QDL device (VR305) */
9362306a36Sopenharmony_ci	{USB_DEVICE(0x05c6, 0x9265)},	/* Asus Gobi 2000 Modem device (VR305) */
9462306a36Sopenharmony_ci	{USB_DEVICE(0x05c6, 0x9234)},	/* Top Global Gobi 2000 QDL device (VR306) */
9562306a36Sopenharmony_ci	{USB_DEVICE(0x05c6, 0x9235)},	/* Top Global Gobi 2000 Modem device (VR306) */
9662306a36Sopenharmony_ci	{USB_DEVICE(0x05c6, 0x9274)},	/* iRex Technologies Gobi 2000 QDL device (VR307) */
9762306a36Sopenharmony_ci	{USB_DEVICE(0x05c6, 0x9275)},	/* iRex Technologies Gobi 2000 Modem device (VR307) */
9862306a36Sopenharmony_ci	{USB_DEVICE(0x1199, 0x9000)},	/* Sierra Wireless Gobi 2000 QDL device (VT773) */
9962306a36Sopenharmony_ci	{USB_DEVICE(0x1199, 0x9001)},	/* Sierra Wireless Gobi 2000 Modem device (VT773) */
10062306a36Sopenharmony_ci	{USB_DEVICE(0x1199, 0x9002)},	/* Sierra Wireless Gobi 2000 Modem device (VT773) */
10162306a36Sopenharmony_ci	{USB_DEVICE(0x1199, 0x9003)},	/* Sierra Wireless Gobi 2000 Modem device (VT773) */
10262306a36Sopenharmony_ci	{USB_DEVICE(0x1199, 0x9004)},	/* Sierra Wireless Gobi 2000 Modem device (VT773) */
10362306a36Sopenharmony_ci	{USB_DEVICE(0x1199, 0x9005)},	/* Sierra Wireless Gobi 2000 Modem device (VT773) */
10462306a36Sopenharmony_ci	{USB_DEVICE(0x1199, 0x9006)},	/* Sierra Wireless Gobi 2000 Modem device (VT773) */
10562306a36Sopenharmony_ci	{USB_DEVICE(0x1199, 0x9007)},	/* Sierra Wireless Gobi 2000 Modem device (VT773) */
10662306a36Sopenharmony_ci	{USB_DEVICE(0x1199, 0x9008)},	/* Sierra Wireless Gobi 2000 Modem device (VT773) */
10762306a36Sopenharmony_ci	{USB_DEVICE(0x1199, 0x9009)},	/* Sierra Wireless Gobi 2000 Modem device (VT773) */
10862306a36Sopenharmony_ci	{USB_DEVICE(0x1199, 0x900a)},	/* Sierra Wireless Gobi 2000 Modem device (VT773) */
10962306a36Sopenharmony_ci	{USB_DEVICE(0x1199, 0x9011)},   /* Sierra Wireless Gobi 2000 Modem device (MC8305) */
11062306a36Sopenharmony_ci	{USB_DEVICE(0x16d8, 0x8001)},	/* CMDTech Gobi 2000 QDL device (VU922) */
11162306a36Sopenharmony_ci	{USB_DEVICE(0x16d8, 0x8002)},	/* CMDTech Gobi 2000 Modem device (VU922) */
11262306a36Sopenharmony_ci	{USB_DEVICE(0x05c6, 0x9204)},	/* Gobi 2000 QDL device */
11362306a36Sopenharmony_ci	{USB_DEVICE(0x05c6, 0x9205)},	/* Gobi 2000 Modem device */
11462306a36Sopenharmony_ci
11562306a36Sopenharmony_ci	/* Gobi 3000 devices */
11662306a36Sopenharmony_ci	{USB_DEVICE(0x03f0, 0x371d)},	/* HP un2430 Gobi 3000 QDL */
11762306a36Sopenharmony_ci	{USB_DEVICE(0x05c6, 0x920c)},	/* Gobi 3000 QDL */
11862306a36Sopenharmony_ci	{USB_DEVICE(0x05c6, 0x920d)},	/* Gobi 3000 Composite */
11962306a36Sopenharmony_ci	{USB_DEVICE(0x1410, 0xa020)},   /* Novatel Gobi 3000 QDL */
12062306a36Sopenharmony_ci	{USB_DEVICE(0x1410, 0xa021)},	/* Novatel Gobi 3000 Composite */
12162306a36Sopenharmony_ci	{USB_DEVICE(0x413c, 0x8193)},	/* Dell Gobi 3000 QDL */
12262306a36Sopenharmony_ci	{USB_DEVICE(0x413c, 0x8194)},	/* Dell Gobi 3000 Composite */
12362306a36Sopenharmony_ci	{USB_DEVICE(0x413c, 0x81a6)},	/* Dell DW5570 QDL (MC8805) */
12462306a36Sopenharmony_ci	{USB_DEVICE(0x1199, 0x68a4)},	/* Sierra Wireless QDL */
12562306a36Sopenharmony_ci	{USB_DEVICE(0x1199, 0x68a5)},	/* Sierra Wireless Modem */
12662306a36Sopenharmony_ci	{USB_DEVICE(0x1199, 0x68a8)},	/* Sierra Wireless QDL */
12762306a36Sopenharmony_ci	{USB_DEVICE(0x1199, 0x68a9)},	/* Sierra Wireless Modem */
12862306a36Sopenharmony_ci	{USB_DEVICE(0x1199, 0x9010)},	/* Sierra Wireless Gobi 3000 QDL */
12962306a36Sopenharmony_ci	{USB_DEVICE(0x1199, 0x9012)},	/* Sierra Wireless Gobi 3000 QDL */
13062306a36Sopenharmony_ci	{USB_DEVICE(0x1199, 0x9013)},	/* Sierra Wireless Gobi 3000 Modem device (MC8355) */
13162306a36Sopenharmony_ci	{USB_DEVICE(0x1199, 0x9014)},	/* Sierra Wireless Gobi 3000 QDL */
13262306a36Sopenharmony_ci	{USB_DEVICE(0x1199, 0x9015)},	/* Sierra Wireless Gobi 3000 Modem device */
13362306a36Sopenharmony_ci	{USB_DEVICE(0x1199, 0x9018)},	/* Sierra Wireless Gobi 3000 QDL */
13462306a36Sopenharmony_ci	{USB_DEVICE(0x1199, 0x9019)},	/* Sierra Wireless Gobi 3000 Modem device */
13562306a36Sopenharmony_ci	{USB_DEVICE(0x1199, 0x901b)},	/* Sierra Wireless MC7770 */
13662306a36Sopenharmony_ci	{USB_DEVICE(0x12D1, 0x14F0)},	/* Sony Gobi 3000 QDL */
13762306a36Sopenharmony_ci	{USB_DEVICE(0x12D1, 0x14F1)},	/* Sony Gobi 3000 Composite */
13862306a36Sopenharmony_ci	{USB_DEVICE(0x0AF0, 0x8120)},	/* Option GTM681W */
13962306a36Sopenharmony_ci
14062306a36Sopenharmony_ci	/* non-Gobi Sierra Wireless devices */
14162306a36Sopenharmony_ci	{DEVICE_SWI(0x03f0, 0x4e1d)},	/* HP lt4111 LTE/EV-DO/HSPA+ Gobi 4G Module */
14262306a36Sopenharmony_ci	{DEVICE_SWI(0x0f3d, 0x68a2)},	/* Sierra Wireless MC7700 */
14362306a36Sopenharmony_ci	{DEVICE_SWI(0x114f, 0x68a2)},	/* Sierra Wireless MC7750 */
14462306a36Sopenharmony_ci	{DEVICE_SWI(0x1199, 0x68a2)},	/* Sierra Wireless MC7710 */
14562306a36Sopenharmony_ci	{DEVICE_SWI(0x1199, 0x68c0)},	/* Sierra Wireless MC7304/MC7354 */
14662306a36Sopenharmony_ci	{DEVICE_SWI(0x1199, 0x901c)},	/* Sierra Wireless EM7700 */
14762306a36Sopenharmony_ci	{DEVICE_SWI(0x1199, 0x901e)},	/* Sierra Wireless EM7355 QDL */
14862306a36Sopenharmony_ci	{DEVICE_SWI(0x1199, 0x901f)},	/* Sierra Wireless EM7355 */
14962306a36Sopenharmony_ci	{DEVICE_SWI(0x1199, 0x9040)},	/* Sierra Wireless Modem */
15062306a36Sopenharmony_ci	{DEVICE_SWI(0x1199, 0x9041)},	/* Sierra Wireless MC7305/MC7355 */
15162306a36Sopenharmony_ci	{DEVICE_SWI(0x1199, 0x9051)},	/* Netgear AirCard 340U */
15262306a36Sopenharmony_ci	{DEVICE_SWI(0x1199, 0x9053)},	/* Sierra Wireless Modem */
15362306a36Sopenharmony_ci	{DEVICE_SWI(0x1199, 0x9054)},	/* Sierra Wireless Modem */
15462306a36Sopenharmony_ci	{DEVICE_SWI(0x1199, 0x9055)},	/* Netgear AirCard 341U */
15562306a36Sopenharmony_ci	{DEVICE_SWI(0x1199, 0x9056)},	/* Sierra Wireless Modem */
15662306a36Sopenharmony_ci	{DEVICE_SWI(0x1199, 0x9060)},	/* Sierra Wireless Modem */
15762306a36Sopenharmony_ci	{DEVICE_SWI(0x1199, 0x9061)},	/* Sierra Wireless Modem */
15862306a36Sopenharmony_ci	{DEVICE_SWI(0x1199, 0x9062)},	/* Sierra Wireless EM7305 QDL */
15962306a36Sopenharmony_ci	{DEVICE_SWI(0x1199, 0x9063)},	/* Sierra Wireless EM7305 */
16062306a36Sopenharmony_ci	{DEVICE_SWI(0x1199, 0x9070)},	/* Sierra Wireless MC74xx */
16162306a36Sopenharmony_ci	{DEVICE_SWI(0x1199, 0x9071)},	/* Sierra Wireless MC74xx */
16262306a36Sopenharmony_ci	{DEVICE_SWI(0x1199, 0x9078)},	/* Sierra Wireless EM74xx */
16362306a36Sopenharmony_ci	{DEVICE_SWI(0x1199, 0x9079)},	/* Sierra Wireless EM74xx */
16462306a36Sopenharmony_ci	{DEVICE_SWI(0x1199, 0x907a)},	/* Sierra Wireless EM74xx QDL */
16562306a36Sopenharmony_ci	{DEVICE_SWI(0x1199, 0x907b)},	/* Sierra Wireless EM74xx */
16662306a36Sopenharmony_ci	{DEVICE_SWI(0x1199, 0x9090)},	/* Sierra Wireless EM7565 QDL */
16762306a36Sopenharmony_ci	{DEVICE_SWI(0x1199, 0x9091)},	/* Sierra Wireless EM7565 */
16862306a36Sopenharmony_ci	{DEVICE_SWI(0x1199, 0x90d2)},	/* Sierra Wireless EM9191 QDL */
16962306a36Sopenharmony_ci	{DEVICE_SWI(0x1199, 0xc080)},	/* Sierra Wireless EM7590 QDL */
17062306a36Sopenharmony_ci	{DEVICE_SWI(0x1199, 0xc081)},	/* Sierra Wireless EM7590 */
17162306a36Sopenharmony_ci	{DEVICE_SWI(0x413c, 0x81a2)},	/* Dell Wireless 5806 Gobi(TM) 4G LTE Mobile Broadband Card */
17262306a36Sopenharmony_ci	{DEVICE_SWI(0x413c, 0x81a3)},	/* Dell Wireless 5570 HSPA+ (42Mbps) Mobile Broadband Card */
17362306a36Sopenharmony_ci	{DEVICE_SWI(0x413c, 0x81a4)},	/* Dell Wireless 5570e HSPA+ (42Mbps) Mobile Broadband Card */
17462306a36Sopenharmony_ci	{DEVICE_SWI(0x413c, 0x81a8)},	/* Dell Wireless 5808 Gobi(TM) 4G LTE Mobile Broadband Card */
17562306a36Sopenharmony_ci	{DEVICE_SWI(0x413c, 0x81a9)},	/* Dell Wireless 5808e Gobi(TM) 4G LTE Mobile Broadband Card */
17662306a36Sopenharmony_ci	{DEVICE_SWI(0x413c, 0x81b1)},	/* Dell Wireless 5809e Gobi(TM) 4G LTE Mobile Broadband Card */
17762306a36Sopenharmony_ci	{DEVICE_SWI(0x413c, 0x81b3)},	/* Dell Wireless 5809e Gobi(TM) 4G LTE Mobile Broadband Card (rev3) */
17862306a36Sopenharmony_ci	{DEVICE_SWI(0x413c, 0x81b5)},	/* Dell Wireless 5811e QDL */
17962306a36Sopenharmony_ci	{DEVICE_SWI(0x413c, 0x81b6)},	/* Dell Wireless 5811e QDL */
18062306a36Sopenharmony_ci	{DEVICE_SWI(0x413c, 0x81c2)},	/* Dell Wireless 5811e */
18162306a36Sopenharmony_ci	{DEVICE_SWI(0x413c, 0x81cb)},	/* Dell Wireless 5816e QDL */
18262306a36Sopenharmony_ci	{DEVICE_SWI(0x413c, 0x81cc)},	/* Dell Wireless 5816e */
18362306a36Sopenharmony_ci	{DEVICE_SWI(0x413c, 0x81cf)},   /* Dell Wireless 5819 */
18462306a36Sopenharmony_ci	{DEVICE_SWI(0x413c, 0x81d0)},   /* Dell Wireless 5819 */
18562306a36Sopenharmony_ci	{DEVICE_SWI(0x413c, 0x81d1)},   /* Dell Wireless 5818 */
18662306a36Sopenharmony_ci	{DEVICE_SWI(0x413c, 0x81d2)},   /* Dell Wireless 5818 */
18762306a36Sopenharmony_ci	{DEVICE_SWI(0x413c, 0x8217)},	/* Dell Wireless DW5826e */
18862306a36Sopenharmony_ci	{DEVICE_SWI(0x413c, 0x8218)},	/* Dell Wireless DW5826e QDL */
18962306a36Sopenharmony_ci
19062306a36Sopenharmony_ci	/* Huawei devices */
19162306a36Sopenharmony_ci	{DEVICE_HWI(0x03f0, 0x581d)},	/* HP lt4112 LTE/HSPA+ Gobi 4G Modem (Huawei me906e) */
19262306a36Sopenharmony_ci
19362306a36Sopenharmony_ci	{ }				/* Terminating entry */
19462306a36Sopenharmony_ci};
19562306a36Sopenharmony_ciMODULE_DEVICE_TABLE(usb, id_table);
19662306a36Sopenharmony_ci
19762306a36Sopenharmony_cistatic int handle_quectel_ec20(struct device *dev, int ifnum)
19862306a36Sopenharmony_ci{
19962306a36Sopenharmony_ci	int altsetting = 0;
20062306a36Sopenharmony_ci
20162306a36Sopenharmony_ci	/*
20262306a36Sopenharmony_ci	 * Quectel EC20 Mini PCIe LTE module layout:
20362306a36Sopenharmony_ci	 * 0: DM/DIAG (use libqcdm from ModemManager for communication)
20462306a36Sopenharmony_ci	 * 1: NMEA
20562306a36Sopenharmony_ci	 * 2: AT-capable modem port
20662306a36Sopenharmony_ci	 * 3: Modem interface
20762306a36Sopenharmony_ci	 * 4: NDIS
20862306a36Sopenharmony_ci	 */
20962306a36Sopenharmony_ci	switch (ifnum) {
21062306a36Sopenharmony_ci	case 0:
21162306a36Sopenharmony_ci		dev_dbg(dev, "Quectel EC20 DM/DIAG interface found\n");
21262306a36Sopenharmony_ci		break;
21362306a36Sopenharmony_ci	case 1:
21462306a36Sopenharmony_ci		dev_dbg(dev, "Quectel EC20 NMEA GPS interface found\n");
21562306a36Sopenharmony_ci		break;
21662306a36Sopenharmony_ci	case 2:
21762306a36Sopenharmony_ci	case 3:
21862306a36Sopenharmony_ci		dev_dbg(dev, "Quectel EC20 Modem port found\n");
21962306a36Sopenharmony_ci		break;
22062306a36Sopenharmony_ci	case 4:
22162306a36Sopenharmony_ci		/* Don't claim the QMI/net interface */
22262306a36Sopenharmony_ci		altsetting = -1;
22362306a36Sopenharmony_ci		break;
22462306a36Sopenharmony_ci	}
22562306a36Sopenharmony_ci
22662306a36Sopenharmony_ci	return altsetting;
22762306a36Sopenharmony_ci}
22862306a36Sopenharmony_ci
22962306a36Sopenharmony_cistatic int qcprobe(struct usb_serial *serial, const struct usb_device_id *id)
23062306a36Sopenharmony_ci{
23162306a36Sopenharmony_ci	struct usb_host_interface *intf = serial->interface->cur_altsetting;
23262306a36Sopenharmony_ci	struct device *dev = &serial->dev->dev;
23362306a36Sopenharmony_ci	int retval = -ENODEV;
23462306a36Sopenharmony_ci	__u8 nintf;
23562306a36Sopenharmony_ci	__u8 ifnum;
23662306a36Sopenharmony_ci	int altsetting = -1;
23762306a36Sopenharmony_ci	bool sendsetup = false;
23862306a36Sopenharmony_ci
23962306a36Sopenharmony_ci	/* we only support vendor specific functions */
24062306a36Sopenharmony_ci	if (intf->desc.bInterfaceClass != USB_CLASS_VENDOR_SPEC)
24162306a36Sopenharmony_ci		goto done;
24262306a36Sopenharmony_ci
24362306a36Sopenharmony_ci	nintf = serial->dev->actconfig->desc.bNumInterfaces;
24462306a36Sopenharmony_ci	dev_dbg(dev, "Num Interfaces = %d\n", nintf);
24562306a36Sopenharmony_ci	ifnum = intf->desc.bInterfaceNumber;
24662306a36Sopenharmony_ci	dev_dbg(dev, "This Interface = %d\n", ifnum);
24762306a36Sopenharmony_ci
24862306a36Sopenharmony_ci	if (nintf == 1) {
24962306a36Sopenharmony_ci		/* QDL mode */
25062306a36Sopenharmony_ci		/* Gobi 2000 has a single altsetting, older ones have two */
25162306a36Sopenharmony_ci		if (serial->interface->num_altsetting == 2)
25262306a36Sopenharmony_ci			intf = usb_altnum_to_altsetting(serial->interface, 1);
25362306a36Sopenharmony_ci		else if (serial->interface->num_altsetting > 2)
25462306a36Sopenharmony_ci			goto done;
25562306a36Sopenharmony_ci
25662306a36Sopenharmony_ci		if (intf && intf->desc.bNumEndpoints == 2 &&
25762306a36Sopenharmony_ci		    usb_endpoint_is_bulk_in(&intf->endpoint[0].desc) &&
25862306a36Sopenharmony_ci		    usb_endpoint_is_bulk_out(&intf->endpoint[1].desc)) {
25962306a36Sopenharmony_ci			dev_dbg(dev, "QDL port found\n");
26062306a36Sopenharmony_ci
26162306a36Sopenharmony_ci			if (serial->interface->num_altsetting == 1)
26262306a36Sopenharmony_ci				retval = 0; /* Success */
26362306a36Sopenharmony_ci			else
26462306a36Sopenharmony_ci				altsetting = 1;
26562306a36Sopenharmony_ci		}
26662306a36Sopenharmony_ci		goto done;
26762306a36Sopenharmony_ci
26862306a36Sopenharmony_ci	}
26962306a36Sopenharmony_ci
27062306a36Sopenharmony_ci	/* default to enabling interface */
27162306a36Sopenharmony_ci	altsetting = 0;
27262306a36Sopenharmony_ci
27362306a36Sopenharmony_ci	/*
27462306a36Sopenharmony_ci	 * Composite mode; don't bind to the QMI/net interface as that
27562306a36Sopenharmony_ci	 * gets handled by other drivers.
27662306a36Sopenharmony_ci	 */
27762306a36Sopenharmony_ci
27862306a36Sopenharmony_ci	switch (id->driver_info) {
27962306a36Sopenharmony_ci	case QCSERIAL_G1K:
28062306a36Sopenharmony_ci		/*
28162306a36Sopenharmony_ci		 * Gobi 1K USB layout:
28262306a36Sopenharmony_ci		 * 0: DM/DIAG (use libqcdm from ModemManager for communication)
28362306a36Sopenharmony_ci		 * 1: serial port (doesn't respond)
28462306a36Sopenharmony_ci		 * 2: AT-capable modem port
28562306a36Sopenharmony_ci		 * 3: QMI/net
28662306a36Sopenharmony_ci		 */
28762306a36Sopenharmony_ci		if (nintf < 3 || nintf > 4) {
28862306a36Sopenharmony_ci			dev_err(dev, "unknown number of interfaces: %d\n", nintf);
28962306a36Sopenharmony_ci			altsetting = -1;
29062306a36Sopenharmony_ci			goto done;
29162306a36Sopenharmony_ci		}
29262306a36Sopenharmony_ci
29362306a36Sopenharmony_ci		if (ifnum == 0) {
29462306a36Sopenharmony_ci			dev_dbg(dev, "Gobi 1K DM/DIAG interface found\n");
29562306a36Sopenharmony_ci			altsetting = 1;
29662306a36Sopenharmony_ci		} else if (ifnum == 2)
29762306a36Sopenharmony_ci			dev_dbg(dev, "Modem port found\n");
29862306a36Sopenharmony_ci		else
29962306a36Sopenharmony_ci			altsetting = -1;
30062306a36Sopenharmony_ci		break;
30162306a36Sopenharmony_ci	case QCSERIAL_G2K:
30262306a36Sopenharmony_ci		/* handle non-standard layouts */
30362306a36Sopenharmony_ci		if (nintf == 5 && id->idProduct == QUECTEL_EC20_PID) {
30462306a36Sopenharmony_ci			altsetting = handle_quectel_ec20(dev, ifnum);
30562306a36Sopenharmony_ci			goto done;
30662306a36Sopenharmony_ci		}
30762306a36Sopenharmony_ci
30862306a36Sopenharmony_ci		/*
30962306a36Sopenharmony_ci		 * Gobi 2K+ USB layout:
31062306a36Sopenharmony_ci		 * 0: QMI/net
31162306a36Sopenharmony_ci		 * 1: DM/DIAG (use libqcdm from ModemManager for communication)
31262306a36Sopenharmony_ci		 * 2: AT-capable modem port
31362306a36Sopenharmony_ci		 * 3: NMEA
31462306a36Sopenharmony_ci		 */
31562306a36Sopenharmony_ci		if (nintf < 3 || nintf > 4) {
31662306a36Sopenharmony_ci			dev_err(dev, "unknown number of interfaces: %d\n", nintf);
31762306a36Sopenharmony_ci			altsetting = -1;
31862306a36Sopenharmony_ci			goto done;
31962306a36Sopenharmony_ci		}
32062306a36Sopenharmony_ci
32162306a36Sopenharmony_ci		switch (ifnum) {
32262306a36Sopenharmony_ci		case 0:
32362306a36Sopenharmony_ci			/* Don't claim the QMI/net interface */
32462306a36Sopenharmony_ci			altsetting = -1;
32562306a36Sopenharmony_ci			break;
32662306a36Sopenharmony_ci		case 1:
32762306a36Sopenharmony_ci			dev_dbg(dev, "Gobi 2K+ DM/DIAG interface found\n");
32862306a36Sopenharmony_ci			break;
32962306a36Sopenharmony_ci		case 2:
33062306a36Sopenharmony_ci			dev_dbg(dev, "Modem port found\n");
33162306a36Sopenharmony_ci			break;
33262306a36Sopenharmony_ci		case 3:
33362306a36Sopenharmony_ci			/*
33462306a36Sopenharmony_ci			 * NMEA (serial line 9600 8N1)
33562306a36Sopenharmony_ci			 * # echo "\$GPS_START" > /dev/ttyUSBx
33662306a36Sopenharmony_ci			 * # echo "\$GPS_STOP"  > /dev/ttyUSBx
33762306a36Sopenharmony_ci			 */
33862306a36Sopenharmony_ci			dev_dbg(dev, "Gobi 2K+ NMEA GPS interface found\n");
33962306a36Sopenharmony_ci			break;
34062306a36Sopenharmony_ci		}
34162306a36Sopenharmony_ci		break;
34262306a36Sopenharmony_ci	case QCSERIAL_SWI:
34362306a36Sopenharmony_ci		/*
34462306a36Sopenharmony_ci		 * Sierra Wireless layout:
34562306a36Sopenharmony_ci		 * 0: DM/DIAG (use libqcdm from ModemManager for communication)
34662306a36Sopenharmony_ci		 * 2: NMEA
34762306a36Sopenharmony_ci		 * 3: AT-capable modem port
34862306a36Sopenharmony_ci		 * 8: QMI/net
34962306a36Sopenharmony_ci		 */
35062306a36Sopenharmony_ci		switch (ifnum) {
35162306a36Sopenharmony_ci		case 0:
35262306a36Sopenharmony_ci			dev_dbg(dev, "DM/DIAG interface found\n");
35362306a36Sopenharmony_ci			break;
35462306a36Sopenharmony_ci		case 2:
35562306a36Sopenharmony_ci			dev_dbg(dev, "NMEA GPS interface found\n");
35662306a36Sopenharmony_ci			sendsetup = true;
35762306a36Sopenharmony_ci			break;
35862306a36Sopenharmony_ci		case 3:
35962306a36Sopenharmony_ci			dev_dbg(dev, "Modem port found\n");
36062306a36Sopenharmony_ci			sendsetup = true;
36162306a36Sopenharmony_ci			break;
36262306a36Sopenharmony_ci		default:
36362306a36Sopenharmony_ci			/* don't claim any unsupported interface */
36462306a36Sopenharmony_ci			altsetting = -1;
36562306a36Sopenharmony_ci			break;
36662306a36Sopenharmony_ci		}
36762306a36Sopenharmony_ci		break;
36862306a36Sopenharmony_ci	case QCSERIAL_HWI:
36962306a36Sopenharmony_ci		/*
37062306a36Sopenharmony_ci		 * Huawei devices map functions by subclass + protocol
37162306a36Sopenharmony_ci		 * instead of interface numbers. The protocol identify
37262306a36Sopenharmony_ci		 * a specific function, while the subclass indicate a
37362306a36Sopenharmony_ci		 * specific firmware source
37462306a36Sopenharmony_ci		 *
37562306a36Sopenharmony_ci		 * This is a list of functions known to be non-serial.  The rest
37662306a36Sopenharmony_ci		 * are assumed to be serial and will be handled by this driver
37762306a36Sopenharmony_ci		 */
37862306a36Sopenharmony_ci		switch (intf->desc.bInterfaceProtocol) {
37962306a36Sopenharmony_ci			/* QMI combined (qmi_wwan) */
38062306a36Sopenharmony_ci		case 0x07:
38162306a36Sopenharmony_ci		case 0x37:
38262306a36Sopenharmony_ci		case 0x67:
38362306a36Sopenharmony_ci			/* QMI data (qmi_wwan) */
38462306a36Sopenharmony_ci		case 0x08:
38562306a36Sopenharmony_ci		case 0x38:
38662306a36Sopenharmony_ci		case 0x68:
38762306a36Sopenharmony_ci			/* QMI control (qmi_wwan) */
38862306a36Sopenharmony_ci		case 0x09:
38962306a36Sopenharmony_ci		case 0x39:
39062306a36Sopenharmony_ci		case 0x69:
39162306a36Sopenharmony_ci			/* NCM like (huawei_cdc_ncm) */
39262306a36Sopenharmony_ci		case 0x16:
39362306a36Sopenharmony_ci		case 0x46:
39462306a36Sopenharmony_ci		case 0x76:
39562306a36Sopenharmony_ci			altsetting = -1;
39662306a36Sopenharmony_ci			break;
39762306a36Sopenharmony_ci		default:
39862306a36Sopenharmony_ci			dev_dbg(dev, "Huawei type serial port found (%02x/%02x/%02x)\n",
39962306a36Sopenharmony_ci				intf->desc.bInterfaceClass,
40062306a36Sopenharmony_ci				intf->desc.bInterfaceSubClass,
40162306a36Sopenharmony_ci				intf->desc.bInterfaceProtocol);
40262306a36Sopenharmony_ci		}
40362306a36Sopenharmony_ci		break;
40462306a36Sopenharmony_ci	default:
40562306a36Sopenharmony_ci		dev_err(dev, "unsupported device layout type: %lu\n",
40662306a36Sopenharmony_ci			id->driver_info);
40762306a36Sopenharmony_ci		break;
40862306a36Sopenharmony_ci	}
40962306a36Sopenharmony_ci
41062306a36Sopenharmony_cidone:
41162306a36Sopenharmony_ci	if (altsetting >= 0) {
41262306a36Sopenharmony_ci		retval = usb_set_interface(serial->dev, ifnum, altsetting);
41362306a36Sopenharmony_ci		if (retval < 0) {
41462306a36Sopenharmony_ci			dev_err(dev,
41562306a36Sopenharmony_ci				"Could not set interface, error %d\n",
41662306a36Sopenharmony_ci				retval);
41762306a36Sopenharmony_ci			retval = -ENODEV;
41862306a36Sopenharmony_ci		}
41962306a36Sopenharmony_ci	}
42062306a36Sopenharmony_ci
42162306a36Sopenharmony_ci	if (!retval)
42262306a36Sopenharmony_ci		usb_set_serial_data(serial, (void *)(unsigned long)sendsetup);
42362306a36Sopenharmony_ci
42462306a36Sopenharmony_ci	return retval;
42562306a36Sopenharmony_ci}
42662306a36Sopenharmony_ci
42762306a36Sopenharmony_cistatic int qc_attach(struct usb_serial *serial)
42862306a36Sopenharmony_ci{
42962306a36Sopenharmony_ci	struct usb_wwan_intf_private *data;
43062306a36Sopenharmony_ci	bool sendsetup;
43162306a36Sopenharmony_ci
43262306a36Sopenharmony_ci	data = kzalloc(sizeof(*data), GFP_KERNEL);
43362306a36Sopenharmony_ci	if (!data)
43462306a36Sopenharmony_ci		return -ENOMEM;
43562306a36Sopenharmony_ci
43662306a36Sopenharmony_ci	sendsetup = !!(unsigned long)(usb_get_serial_data(serial));
43762306a36Sopenharmony_ci	if (sendsetup)
43862306a36Sopenharmony_ci		data->use_send_setup = 1;
43962306a36Sopenharmony_ci
44062306a36Sopenharmony_ci	spin_lock_init(&data->susp_lock);
44162306a36Sopenharmony_ci
44262306a36Sopenharmony_ci	usb_set_serial_data(serial, data);
44362306a36Sopenharmony_ci
44462306a36Sopenharmony_ci	return 0;
44562306a36Sopenharmony_ci}
44662306a36Sopenharmony_ci
44762306a36Sopenharmony_cistatic void qc_release(struct usb_serial *serial)
44862306a36Sopenharmony_ci{
44962306a36Sopenharmony_ci	struct usb_wwan_intf_private *priv = usb_get_serial_data(serial);
45062306a36Sopenharmony_ci
45162306a36Sopenharmony_ci	usb_set_serial_data(serial, NULL);
45262306a36Sopenharmony_ci	kfree(priv);
45362306a36Sopenharmony_ci}
45462306a36Sopenharmony_ci
45562306a36Sopenharmony_cistatic struct usb_serial_driver qcdevice = {
45662306a36Sopenharmony_ci	.driver = {
45762306a36Sopenharmony_ci		.owner     = THIS_MODULE,
45862306a36Sopenharmony_ci		.name      = "qcserial",
45962306a36Sopenharmony_ci	},
46062306a36Sopenharmony_ci	.description         = "Qualcomm USB modem",
46162306a36Sopenharmony_ci	.id_table            = id_table,
46262306a36Sopenharmony_ci	.num_ports           = 1,
46362306a36Sopenharmony_ci	.probe               = qcprobe,
46462306a36Sopenharmony_ci	.open		     = usb_wwan_open,
46562306a36Sopenharmony_ci	.close		     = usb_wwan_close,
46662306a36Sopenharmony_ci	.dtr_rts	     = usb_wwan_dtr_rts,
46762306a36Sopenharmony_ci	.write		     = usb_wwan_write,
46862306a36Sopenharmony_ci	.write_room	     = usb_wwan_write_room,
46962306a36Sopenharmony_ci	.chars_in_buffer     = usb_wwan_chars_in_buffer,
47062306a36Sopenharmony_ci	.tiocmget            = usb_wwan_tiocmget,
47162306a36Sopenharmony_ci	.tiocmset            = usb_wwan_tiocmset,
47262306a36Sopenharmony_ci	.attach              = qc_attach,
47362306a36Sopenharmony_ci	.release	     = qc_release,
47462306a36Sopenharmony_ci	.port_probe          = usb_wwan_port_probe,
47562306a36Sopenharmony_ci	.port_remove	     = usb_wwan_port_remove,
47662306a36Sopenharmony_ci#ifdef CONFIG_PM
47762306a36Sopenharmony_ci	.suspend	     = usb_wwan_suspend,
47862306a36Sopenharmony_ci	.resume		     = usb_wwan_resume,
47962306a36Sopenharmony_ci#endif
48062306a36Sopenharmony_ci};
48162306a36Sopenharmony_ci
48262306a36Sopenharmony_cistatic struct usb_serial_driver * const serial_drivers[] = {
48362306a36Sopenharmony_ci	&qcdevice, NULL
48462306a36Sopenharmony_ci};
48562306a36Sopenharmony_ci
48662306a36Sopenharmony_cimodule_usb_serial_driver(serial_drivers, id_table);
48762306a36Sopenharmony_ci
48862306a36Sopenharmony_ciMODULE_AUTHOR(DRIVER_AUTHOR);
48962306a36Sopenharmony_ciMODULE_DESCRIPTION(DRIVER_DESC);
49062306a36Sopenharmony_ciMODULE_LICENSE("GPL v2");
491