1f9f848faSopenharmony_ci/*
2f9f848faSopenharmony_ci * Copyright (c) 2008 AnyWi Technologies
3f9f848faSopenharmony_ci * Author: Andrea Guzzo <aguzzo@anywi.com>
4f9f848faSopenharmony_ci * * based on uark.c 1.1 2006/08/14 08:30:22 jsg *
5f9f848faSopenharmony_ci * * parts from ubsa.c 183348 2008-09-25 12:00:56Z phk *
6f9f848faSopenharmony_ci *
7f9f848faSopenharmony_ci * Permission to use, copy, modify, and distribute this software for any
8f9f848faSopenharmony_ci * purpose with or without fee is hereby granted, provided that the above
9f9f848faSopenharmony_ci * copyright notice and this permission notice appear in all copies.
10f9f848faSopenharmony_ci *
11f9f848faSopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12f9f848faSopenharmony_ci * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13f9f848faSopenharmony_ci * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14f9f848faSopenharmony_ci * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15f9f848faSopenharmony_ci * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16f9f848faSopenharmony_ci * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17f9f848faSopenharmony_ci * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18f9f848faSopenharmony_ci */
19f9f848faSopenharmony_ci
20f9f848faSopenharmony_ci/*
21f9f848faSopenharmony_ci * NOTE:
22f9f848faSopenharmony_ci *
23f9f848faSopenharmony_ci * - The detour through the tty layer is ridiculously expensive wrt
24f9f848faSopenharmony_ci *   buffering due to the high speeds.
25f9f848faSopenharmony_ci *
26f9f848faSopenharmony_ci *   We should consider adding a simple r/w device which allows
27f9f848faSopenharmony_ci *   attaching of PPP in a more efficient way.
28f9f848faSopenharmony_ci *
29f9f848faSopenharmony_ci */
30f9f848faSopenharmony_ci
31f9f848faSopenharmony_ci#include <los_queue.h>
32f9f848faSopenharmony_ci
33f9f848faSopenharmony_ci#include "implementation/global_implementation.h"
34f9f848faSopenharmony_ci#include "implementation/usbdevs.h"
35f9f848faSopenharmony_ci#include "usb_serial.h"
36f9f848faSopenharmony_ci
37f9f848faSopenharmony_ci#undef USB_DEBUG_VAR
38f9f848faSopenharmony_ci#define	USB_DEBUG_VAR   u3g_debug
39f9f848faSopenharmony_ci#ifdef LOSCFG_USB_DEBUG
40f9f848faSopenharmony_cistatic int u3g_debug = 0;
41f9f848faSopenharmony_civoid
42f9f848faSopenharmony_ciu3g_debug_func(int level)
43f9f848faSopenharmony_ci{
44f9f848faSopenharmony_ci	u3g_debug = level;
45f9f848faSopenharmony_ci	PRINTK("The level of u3g debug is %d\n", level);
46f9f848faSopenharmony_ci}
47f9f848faSopenharmony_ciDEBUG_MODULE(u3g, u3g_debug_func);
48f9f848faSopenharmony_ci#endif
49f9f848faSopenharmony_ci
50f9f848faSopenharmony_ci#define	U3G_MAXPORTS		12
51f9f848faSopenharmony_ci#define	U3G_CONFIG_INDEX	1
52f9f848faSopenharmony_ci#define	U3G_BSIZE		2048
53f9f848faSopenharmony_ci#define	U3G_TXSIZE		(U3G_BSIZE / U3G_TXFRAMES)
54f9f848faSopenharmony_ci#define	U3G_TXFRAMES		4
55f9f848faSopenharmony_ci
56f9f848faSopenharmony_ci#define	U3GSP_GPRS		0
57f9f848faSopenharmony_ci#define	U3GSP_EDGE		1
58f9f848faSopenharmony_ci#define	U3GSP_CDMA		2
59f9f848faSopenharmony_ci#define	U3GSP_UMTS		3
60f9f848faSopenharmony_ci#define	U3GSP_HSDPA		4
61f9f848faSopenharmony_ci#define	U3GSP_HSUPA		5
62f9f848faSopenharmony_ci#define	U3GSP_HSPA		6
63f9f848faSopenharmony_ci#define	U3GSP_MAX		7
64f9f848faSopenharmony_ci
65f9f848faSopenharmony_ci/* Eject methods; See also usb_quirks.h:UQ_MSC_EJECT_* */
66f9f848faSopenharmony_ci#define	U3GINIT_HUAWEI		1	/* Requires Huawei init command */
67f9f848faSopenharmony_ci#define	U3GINIT_SIERRA		2	/* Requires Sierra init command */
68f9f848faSopenharmony_ci#define	U3GINIT_SCSIEJECT	3	/* Requires SCSI eject command */
69f9f848faSopenharmony_ci#define	U3GINIT_REZERO		4	/* Requires SCSI rezero command */
70f9f848faSopenharmony_ci#define	U3GINIT_ZTESTOR		5	/* Requires ZTE SCSI command */
71f9f848faSopenharmony_ci#define	U3GINIT_CMOTECH		6	/* Requires CMOTECH SCSI command */
72f9f848faSopenharmony_ci#define	U3GINIT_WAIT		7	/* Device reappears after a delay */
73f9f848faSopenharmony_ci#define	U3GINIT_SAEL_M460	8	/* Requires vendor init */
74f9f848faSopenharmony_ci#define	U3GINIT_HUAWEISCSI	9	/* Requires Huawei SCSI init command */
75f9f848faSopenharmony_ci#define	 U3GINIT_HUAWEISCSI2 10
76f9f848faSopenharmony_ci#define	 U3GINIT_HUAWEISCSI3 11
77f9f848faSopenharmony_ci#define	U3GINIT_TCT		12		/* Requires TCT Mobile init command */
78f9f848faSopenharmony_ci
79f9f848faSopenharmony_cienum {
80f9f848faSopenharmony_ci	U3G_BULK_WR,
81f9f848faSopenharmony_ci	U3G_BULK_RD,
82f9f848faSopenharmony_ci	U3G_INTR,
83f9f848faSopenharmony_ci	U3G_N_TRANSFER,
84f9f848faSopenharmony_ci};
85f9f848faSopenharmony_ci
86f9f848faSopenharmony_cistruct u3g_softc {
87f9f848faSopenharmony_ci	struct ucom_super_softc sc_super_ucom;
88f9f848faSopenharmony_ci	struct ucom_softc sc_ucom[U3G_MAXPORTS];
89f9f848faSopenharmony_ci
90f9f848faSopenharmony_ci	struct usb_xfer *sc_xfer[U3G_MAXPORTS][U3G_N_TRANSFER];
91f9f848faSopenharmony_ci	uint8_t sc_iface[U3G_MAXPORTS];			/* local status register */
92f9f848faSopenharmony_ci	uint8_t sc_lsr[U3G_MAXPORTS];			/* local status register */
93f9f848faSopenharmony_ci	uint8_t sc_msr[U3G_MAXPORTS];			/* u3g status register */
94f9f848faSopenharmony_ci	uint16_t sc_line[U3G_MAXPORTS];			/* line status */
95f9f848faSopenharmony_ci
96f9f848faSopenharmony_ci	struct usb_device *sc_udev;
97f9f848faSopenharmony_ci	struct mtx sc_mtx;
98f9f848faSopenharmony_ci
99f9f848faSopenharmony_ci	uint8_t sc_numports;
100f9f848faSopenharmony_ci};
101f9f848faSopenharmony_ci
102f9f848faSopenharmony_cistatic device_probe_t u3g_probe;
103f9f848faSopenharmony_cistatic device_attach_t u3g_attach;
104f9f848faSopenharmony_cistatic device_detach_t u3g_detach;
105f9f848faSopenharmony_cistatic void u3g_free_softc(struct u3g_softc *);
106f9f848faSopenharmony_ci
107f9f848faSopenharmony_cistatic usb_callback_t u3g_write_callback;
108f9f848faSopenharmony_cistatic usb_callback_t u3g_read_callback;
109f9f848faSopenharmony_cistatic usb_callback_t u3g_intr_callback;
110f9f848faSopenharmony_ci
111f9f848faSopenharmony_cistatic void u3g_cfg_get_status(struct ucom_softc *, uint8_t *, uint8_t *);
112f9f848faSopenharmony_cistatic void u3g_cfg_set_dtr(struct ucom_softc *, uint8_t);
113f9f848faSopenharmony_cistatic void u3g_cfg_set_rts(struct ucom_softc *, uint8_t);
114f9f848faSopenharmony_cistatic void u3g_start_read(struct ucom_softc *ucom);
115f9f848faSopenharmony_cistatic void u3g_stop_read(struct ucom_softc *ucom);
116f9f848faSopenharmony_cistatic void u3g_start_write(struct ucom_softc *ucom);
117f9f848faSopenharmony_cistatic void u3g_stop_write(struct ucom_softc *ucom);
118f9f848faSopenharmony_cistatic void u3g_poll(struct ucom_softc *ucom);
119f9f848faSopenharmony_cistatic void u3g_free(struct ucom_softc *ucom);
120f9f848faSopenharmony_ci
121f9f848faSopenharmony_cistatic const struct usb_config u3g_config[U3G_N_TRANSFER] = {
122f9f848faSopenharmony_ci	[U3G_BULK_WR] = {
123f9f848faSopenharmony_ci		.type = UE_BULK,
124f9f848faSopenharmony_ci		.endpoint = UE_ADDR_ANY,
125f9f848faSopenharmony_ci		.direction = UE_DIR_OUT,
126f9f848faSopenharmony_ci		.bufsize = U3G_BSIZE,/* bytes */
127f9f848faSopenharmony_ci		.frames = U3G_TXFRAMES,
128f9f848faSopenharmony_ci		.flags = {.pipe_bof = 1,.force_short_xfer = 1,},
129f9f848faSopenharmony_ci		.callback = &u3g_write_callback,
130f9f848faSopenharmony_ci	},
131f9f848faSopenharmony_ci
132f9f848faSopenharmony_ci	[U3G_BULK_RD] = {
133f9f848faSopenharmony_ci		.type = UE_BULK,
134f9f848faSopenharmony_ci		.endpoint = UE_ADDR_ANY,
135f9f848faSopenharmony_ci		.direction = UE_DIR_IN,
136f9f848faSopenharmony_ci		.bufsize = U3G_BSIZE,/* bytes */
137f9f848faSopenharmony_ci		.flags = {.pipe_bof = 1,.short_xfer_ok = 1,},
138f9f848faSopenharmony_ci		.callback = &u3g_read_callback,
139f9f848faSopenharmony_ci	},
140f9f848faSopenharmony_ci
141f9f848faSopenharmony_ci	[U3G_INTR] = {
142f9f848faSopenharmony_ci		.type = UE_INTERRUPT,
143f9f848faSopenharmony_ci		.endpoint = UE_ADDR_ANY,
144f9f848faSopenharmony_ci		.direction = UE_DIR_IN,
145f9f848faSopenharmony_ci		.flags = {.pipe_bof = 1,.short_xfer_ok = 1,.no_pipe_ok = 1,},
146f9f848faSopenharmony_ci		.bufsize = 0,	/* use wMaxPacketSize */
147f9f848faSopenharmony_ci		.callback = &u3g_intr_callback,
148f9f848faSopenharmony_ci	},
149f9f848faSopenharmony_ci};
150f9f848faSopenharmony_ci
151f9f848faSopenharmony_cistatic const struct ucom_callback u3g_callback = {
152f9f848faSopenharmony_ci	.ucom_cfg_get_status = &u3g_cfg_get_status,
153f9f848faSopenharmony_ci	.ucom_cfg_set_dtr = &u3g_cfg_set_dtr,
154f9f848faSopenharmony_ci	.ucom_cfg_set_rts = &u3g_cfg_set_rts,
155f9f848faSopenharmony_ci	.ucom_start_read = &u3g_start_read,
156f9f848faSopenharmony_ci	.ucom_stop_read = &u3g_stop_read,
157f9f848faSopenharmony_ci	.ucom_start_write = &u3g_start_write,
158f9f848faSopenharmony_ci	.ucom_stop_write = &u3g_stop_write,
159f9f848faSopenharmony_ci	.ucom_poll = &u3g_poll,
160f9f848faSopenharmony_ci	.ucom_free = &u3g_free,
161f9f848faSopenharmony_ci};
162f9f848faSopenharmony_ci
163f9f848faSopenharmony_cistatic device_method_t u3g_methods[] = {
164f9f848faSopenharmony_ci	DEVMETHOD(device_probe, u3g_probe),
165f9f848faSopenharmony_ci	DEVMETHOD(device_attach, u3g_attach),
166f9f848faSopenharmony_ci	DEVMETHOD(device_detach, u3g_detach),
167f9f848faSopenharmony_ci	DEVMETHOD_END
168f9f848faSopenharmony_ci};
169f9f848faSopenharmony_ci
170f9f848faSopenharmony_cistatic devclass_t u3g_devclass;
171f9f848faSopenharmony_ci
172f9f848faSopenharmony_cistatic driver_t u3g_driver = {
173f9f848faSopenharmony_ci	.name = "u3g",
174f9f848faSopenharmony_ci	.methods = u3g_methods,
175f9f848faSopenharmony_ci	.size = sizeof(struct u3g_softc),
176f9f848faSopenharmony_ci};
177f9f848faSopenharmony_ci
178f9f848faSopenharmony_ciDRIVER_MODULE(u3g, uhub, u3g_driver, u3g_devclass, 0, 0);
179f9f848faSopenharmony_ci
180f9f848faSopenharmony_cistatic const STRUCT_USB_HOST_ID u3g_devs[] = {
181f9f848faSopenharmony_ci#define	U3G_DEV(v,p,i) { USB_VPI(USB_VENDOR_##v, USB_PRODUCT_##v##_##p, i) }
182f9f848faSopenharmony_ci	U3G_DEV(ABIT, AK_020, 0),
183f9f848faSopenharmony_ci	U3G_DEV(ACERP, H10, 0),
184f9f848faSopenharmony_ci	U3G_DEV(AIRPLUS, MCD650, 0),
185f9f848faSopenharmony_ci	U3G_DEV(AIRPRIME, PC5220, 0),
186f9f848faSopenharmony_ci	U3G_DEV(AIRPRIME, AC313U, 0),
187f9f848faSopenharmony_ci	U3G_DEV(ALINK, 3G, 0),
188f9f848faSopenharmony_ci	U3G_DEV(ALINK, 3GU, 0),
189f9f848faSopenharmony_ci	U3G_DEV(ALINK, DWM652U5, 0),
190f9f848faSopenharmony_ci	U3G_DEV(ALINK, SIM7600E, 0),
191f9f848faSopenharmony_ci	U3G_DEV(AMOI, H01, 0),
192f9f848faSopenharmony_ci	U3G_DEV(AMOI, H01A, 0),
193f9f848faSopenharmony_ci	U3G_DEV(AMOI, H02, 0),
194f9f848faSopenharmony_ci	U3G_DEV(ANYDATA, ADU_500A, 0),
195f9f848faSopenharmony_ci	U3G_DEV(ANYDATA, ADU_620UW, 0),
196f9f848faSopenharmony_ci	U3G_DEV(ANYDATA, ADU_E100X, 0),
197f9f848faSopenharmony_ci	U3G_DEV(AXESSTEL, DATAMODEM, 0),
198f9f848faSopenharmony_ci	U3G_DEV(CMOTECH, CDMA_MODEM1, 0),
199f9f848faSopenharmony_ci	U3G_DEV(CMOTECH, CGU628, U3GINIT_CMOTECH),
200f9f848faSopenharmony_ci	U3G_DEV(DELL, U5500, 0),
201f9f848faSopenharmony_ci	U3G_DEV(DELL, U5505, 0),
202f9f848faSopenharmony_ci	U3G_DEV(DELL, U5510, 0),
203f9f848faSopenharmony_ci	U3G_DEV(DELL, U5520, 0),
204f9f848faSopenharmony_ci	U3G_DEV(DELL, U5520_2, 0),
205f9f848faSopenharmony_ci	U3G_DEV(DELL, U5520_3, 0),
206f9f848faSopenharmony_ci	U3G_DEV(DELL, U5700, 0),
207f9f848faSopenharmony_ci	U3G_DEV(DELL, U5700_2, 0),
208f9f848faSopenharmony_ci	U3G_DEV(DELL, U5700_3, 0),
209f9f848faSopenharmony_ci	U3G_DEV(DELL, U5700_4, 0),
210f9f848faSopenharmony_ci	U3G_DEV(DELL, U5720, 0),
211f9f848faSopenharmony_ci	U3G_DEV(DELL, U5720_2, 0),
212f9f848faSopenharmony_ci	U3G_DEV(DELL, U5730, 0),
213f9f848faSopenharmony_ci	U3G_DEV(DELL, U5730_2, 0),
214f9f848faSopenharmony_ci	U3G_DEV(DELL, U5730_3, 0),
215f9f848faSopenharmony_ci	U3G_DEV(DELL, U740, 0),
216f9f848faSopenharmony_ci	U3G_DEV(DLINK, DWR510_CD, U3GINIT_SCSIEJECT),
217f9f848faSopenharmony_ci	U3G_DEV(DLINK, DWR510, 0),
218f9f848faSopenharmony_ci	U3G_DEV(DLINK, DWM157_CD, U3GINIT_SCSIEJECT),
219f9f848faSopenharmony_ci	U3G_DEV(DLINK, DWM157, 0),
220f9f848faSopenharmony_ci	U3G_DEV(DLINK3, DWM652, 0),
221f9f848faSopenharmony_ci	U3G_DEV(HP, EV2200, 0),
222f9f848faSopenharmony_ci	U3G_DEV(HP, HS2300, 0),
223f9f848faSopenharmony_ci	U3G_DEV(HP, UN2420_QDL, 0),
224f9f848faSopenharmony_ci	U3G_DEV(HP, UN2420, 0),
225f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, E1401, U3GINIT_HUAWEI),
226f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, E1402, U3GINIT_HUAWEI),
227f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, E1403, U3GINIT_HUAWEI),
228f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, E1404, U3GINIT_HUAWEI),
229f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, E1405, U3GINIT_HUAWEI),
230f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, E1406, U3GINIT_HUAWEI),
231f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, E1407, U3GINIT_HUAWEI),
232f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, E1408, U3GINIT_HUAWEI),
233f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, E1409, U3GINIT_HUAWEI),
234f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, E140A, U3GINIT_HUAWEI),
235f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, E140B, U3GINIT_HUAWEI),
236f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, E140D, U3GINIT_HUAWEI),
237f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, E140E, U3GINIT_HUAWEI),
238f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, E140F, U3GINIT_HUAWEI),
239f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, E1410, U3GINIT_HUAWEI),
240f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, E1411, U3GINIT_HUAWEI),
241f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, E1412, U3GINIT_HUAWEI),
242f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, E1413, U3GINIT_HUAWEI),
243f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, E1414, U3GINIT_HUAWEI),
244f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, E1415, U3GINIT_HUAWEI),
245f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, E1416, U3GINIT_HUAWEI),
246f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, E1417, U3GINIT_HUAWEI),
247f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, E1418, U3GINIT_HUAWEI),
248f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, E1419, U3GINIT_HUAWEI),
249f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, E141A, U3GINIT_HUAWEI),
250f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, E141B, U3GINIT_HUAWEI),
251f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, E141C, U3GINIT_HUAWEI),
252f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, E141D, U3GINIT_HUAWEI),
253f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, E141E, U3GINIT_HUAWEI),
254f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, E141F, U3GINIT_HUAWEI),
255f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, E1420, U3GINIT_HUAWEI),
256f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, E1421, U3GINIT_HUAWEI),
257f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, E1422, U3GINIT_HUAWEI),
258f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, E1423, U3GINIT_HUAWEI),
259f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, E1424, U3GINIT_HUAWEI),
260f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, E1425, U3GINIT_HUAWEI),
261f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, E1426, U3GINIT_HUAWEI),
262f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, E1427, U3GINIT_HUAWEI),
263f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, E1428, U3GINIT_HUAWEI),
264f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, E1429, U3GINIT_HUAWEI),
265f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, E142A, U3GINIT_HUAWEI),
266f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, E142B, U3GINIT_HUAWEI),
267f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, E142C, U3GINIT_HUAWEI),
268f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, E142D, U3GINIT_HUAWEI),
269f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, E142E, U3GINIT_HUAWEI),
270f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, E142F, U3GINIT_HUAWEI),
271f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, E1430, U3GINIT_HUAWEI),
272f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, E1431, U3GINIT_HUAWEI),
273f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, E1432, U3GINIT_HUAWEI),
274f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, E1433, U3GINIT_HUAWEI),
275f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, E1434, U3GINIT_HUAWEI),
276f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, E1435, U3GINIT_HUAWEI),
277f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, E1436, U3GINIT_HUAWEI),
278f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, E1437, U3GINIT_HUAWEI),
279f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, E1438, U3GINIT_HUAWEI),
280f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, E1439, U3GINIT_HUAWEI),
281f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, E143A, U3GINIT_HUAWEI),
282f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, E143B, U3GINIT_HUAWEI),
283f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, E143C, U3GINIT_HUAWEI),
284f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, E143D, U3GINIT_HUAWEI),
285f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, E143E, U3GINIT_HUAWEI),
286f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, E143F, U3GINIT_HUAWEI),
287f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, E173, 0),
288f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, E173_INIT, U3GINIT_HUAWEISCSI),
289f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, E3131, 0),
290f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, E3131_INIT, U3GINIT_HUAWEISCSI2),
291f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, E180V, U3GINIT_HUAWEI),
292f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, E220, U3GINIT_HUAWEI),
293f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, E220BIS, U3GINIT_HUAWEI),
294f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, E392, U3GINIT_HUAWEISCSI),
295f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, ME909U, U3GINIT_HUAWEISCSI2),
296f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, ME909S, 0),
297f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, MOBILE, U3GINIT_HUAWEI),
298f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, E1752, U3GINIT_HUAWEISCSI),
299f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, E1820, U3GINIT_HUAWEISCSI),
300f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, K3772, U3GINIT_HUAWEI),
301f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, K3772_INIT, U3GINIT_HUAWEISCSI2),
302f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, K3765, U3GINIT_HUAWEI),
303f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, K3765_INIT, U3GINIT_HUAWEISCSI),
304f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, K3770, U3GINIT_HUAWEI),
305f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, K3770_INIT, U3GINIT_HUAWEISCSI),
306f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, K4505, U3GINIT_HUAWEI),
307f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, K4505_INIT, U3GINIT_HUAWEISCSI),
308f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, ETS2055, U3GINIT_HUAWEI),
309f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, E3272_INIT, U3GINIT_HUAWEISCSI2),
310f9f848faSopenharmony_ci	U3G_DEV(HUAWEI, E3272, 0),
311f9f848faSopenharmony_ci	U3G_DEV(KYOCERA2, CDMA_MSM_K, 0),
312f9f848faSopenharmony_ci	U3G_DEV(KYOCERA2, KPC680, 0),
313f9f848faSopenharmony_ci	U3G_DEV(LONGCHEER, WM66, U3GINIT_HUAWEI),
314f9f848faSopenharmony_ci	U3G_DEV(LONGCHEER, DISK, U3GINIT_TCT),
315f9f848faSopenharmony_ci	U3G_DEV(LONGCHEER, W14, 0),
316f9f848faSopenharmony_ci	U3G_DEV(LONGCHEER, XSSTICK, 0),
317f9f848faSopenharmony_ci	U3G_DEV(MERLIN, V620, 0),
318f9f848faSopenharmony_ci	U3G_DEV(NEOTEL, PRIME, 0),
319f9f848faSopenharmony_ci	U3G_DEV(NOVATEL, E725, 0),
320f9f848faSopenharmony_ci	U3G_DEV(NOVATEL, ES620, 0),
321f9f848faSopenharmony_ci	U3G_DEV(NOVATEL, ES620_2, 0),
322f9f848faSopenharmony_ci	U3G_DEV(NOVATEL, EU730, 0),
323f9f848faSopenharmony_ci	U3G_DEV(NOVATEL, EU740, 0),
324f9f848faSopenharmony_ci	U3G_DEV(NOVATEL, EU870D, 0),
325f9f848faSopenharmony_ci	U3G_DEV(NOVATEL, MC760, 0),
326f9f848faSopenharmony_ci	U3G_DEV(NOVATEL, MC547, 0),
327f9f848faSopenharmony_ci	U3G_DEV(NOVATEL, MC679, 0),
328f9f848faSopenharmony_ci	U3G_DEV(NOVATEL, MC950D, 0),
329f9f848faSopenharmony_ci	U3G_DEV(NOVATEL, MC990D, 0),
330f9f848faSopenharmony_ci	U3G_DEV(NOVATEL, MIFI2200, U3GINIT_SCSIEJECT),
331f9f848faSopenharmony_ci	U3G_DEV(NOVATEL, MIFI2200V, U3GINIT_SCSIEJECT),
332f9f848faSopenharmony_ci	U3G_DEV(NOVATEL, U720, 0),
333f9f848faSopenharmony_ci	U3G_DEV(NOVATEL, U727, 0),
334f9f848faSopenharmony_ci	U3G_DEV(NOVATEL, U727_2, 0),
335f9f848faSopenharmony_ci	U3G_DEV(NOVATEL, U740, 0),
336f9f848faSopenharmony_ci	U3G_DEV(NOVATEL, U740_2, 0),
337f9f848faSopenharmony_ci	U3G_DEV(NOVATEL, U760, U3GINIT_SCSIEJECT),
338f9f848faSopenharmony_ci	U3G_DEV(NOVATEL, U870, 0),
339f9f848faSopenharmony_ci	U3G_DEV(NOVATEL, V620, 0),
340f9f848faSopenharmony_ci	U3G_DEV(NOVATEL, V640, 0),
341f9f848faSopenharmony_ci	U3G_DEV(NOVATEL, V720, 0),
342f9f848faSopenharmony_ci	U3G_DEV(NOVATEL, V740, 0),
343f9f848faSopenharmony_ci	U3G_DEV(NOVATEL, X950D, 0),
344f9f848faSopenharmony_ci	U3G_DEV(NOVATEL, XU870, 0),
345f9f848faSopenharmony_ci	U3G_DEV(MOTOROLA2, MB886, U3GINIT_SCSIEJECT),
346f9f848faSopenharmony_ci	U3G_DEV(OPTION, E6500, 0),
347f9f848faSopenharmony_ci	U3G_DEV(OPTION, E6501, 0),
348f9f848faSopenharmony_ci	U3G_DEV(OPTION, E6601, 0),
349f9f848faSopenharmony_ci	U3G_DEV(OPTION, E6721, 0),
350f9f848faSopenharmony_ci	U3G_DEV(OPTION, E6741, 0),
351f9f848faSopenharmony_ci	U3G_DEV(OPTION, E6761, 0),
352f9f848faSopenharmony_ci	U3G_DEV(OPTION, E6800, 0),
353f9f848faSopenharmony_ci	U3G_DEV(OPTION, E7021, 0),
354f9f848faSopenharmony_ci	U3G_DEV(OPTION, E7041, 0),
355f9f848faSopenharmony_ci	U3G_DEV(OPTION, E7061, 0),
356f9f848faSopenharmony_ci	U3G_DEV(OPTION, E7100, 0),
357f9f848faSopenharmony_ci	U3G_DEV(OPTION, GE40X, 0),
358f9f848faSopenharmony_ci	U3G_DEV(OPTION, GT3G, 0),
359f9f848faSopenharmony_ci	U3G_DEV(OPTION, GT3GPLUS, 0),
360f9f848faSopenharmony_ci	U3G_DEV(OPTION, GT3GQUAD, 0),
361f9f848faSopenharmony_ci	U3G_DEV(OPTION, GT3G_1, 0),
362f9f848faSopenharmony_ci	U3G_DEV(OPTION, GT3G_2, 0),
363f9f848faSopenharmony_ci	U3G_DEV(OPTION, GT3G_3, 0),
364f9f848faSopenharmony_ci	U3G_DEV(OPTION, GT3G_4, 0),
365f9f848faSopenharmony_ci	U3G_DEV(OPTION, GT3G_5, 0),
366f9f848faSopenharmony_ci	U3G_DEV(OPTION, GT3G_6, 0),
367f9f848faSopenharmony_ci	U3G_DEV(OPTION, GTHSDPA, 0),
368f9f848faSopenharmony_ci	U3G_DEV(OPTION, GTM380, 0),
369f9f848faSopenharmony_ci	U3G_DEV(OPTION, GTMAX36, 0),
370f9f848faSopenharmony_ci	U3G_DEV(OPTION, GTMAX380HSUPAE, 0),
371f9f848faSopenharmony_ci	U3G_DEV(OPTION, GTMAXHSUPA, 0),
372f9f848faSopenharmony_ci	U3G_DEV(OPTION, GTMAXHSUPAE, 0),
373f9f848faSopenharmony_ci	U3G_DEV(OPTION, VODAFONEMC3G, 0),
374f9f848faSopenharmony_ci	U3G_DEV(QISDA, H20_1, 0),
375f9f848faSopenharmony_ci	U3G_DEV(QISDA, H20_2, 0),
376f9f848faSopenharmony_ci	U3G_DEV(QISDA, H21_1, 0),
377f9f848faSopenharmony_ci	U3G_DEV(QISDA, H21_2, 0),
378f9f848faSopenharmony_ci	U3G_DEV(QUALCOMM, NTT_L02C_MODEM, U3GINIT_SCSIEJECT),
379f9f848faSopenharmony_ci	U3G_DEV(QUALCOMM2, AC8700, 0),
380f9f848faSopenharmony_ci	U3G_DEV(QUALCOMM2, MF330, 0),
381f9f848faSopenharmony_ci	U3G_DEV(QUALCOMM2, SIM5218, 0),
382f9f848faSopenharmony_ci	U3G_DEV(QUALCOMM2, WM620, 0),
383f9f848faSopenharmony_ci	U3G_DEV(QUALCOMM2, VW110L, U3GINIT_SCSIEJECT),
384f9f848faSopenharmony_ci	U3G_DEV(QUALCOMM2, GOBI2000_QDL, 0),
385f9f848faSopenharmony_ci	U3G_DEV(QUALCOMM2, GOBI2000, 0),
386f9f848faSopenharmony_ci	U3G_DEV(QUALCOMM2, VT80N, 0),
387f9f848faSopenharmony_ci	U3G_DEV(QUALCOMM3, VFAST2, 0),
388f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, AC2726, 0),
389f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, AC682_INIT, U3GINIT_SCSIEJECT),
390f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, AC682, 0),
391f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, AC8700, 0),
392f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, AC8710, 0),
393f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, CDMA_MSM, U3GINIT_SCSIEJECT),
394f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, E0002, 0),
395f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, E0003, 0),
396f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, E0004, 0),
397f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, E0005, 0),
398f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, E0006, 0),
399f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, E0007, 0),
400f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, E0008, 0),
401f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, E0009, 0),
402f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, E000A, 0),
403f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, E000B, 0),
404f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, E000C, 0),
405f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, E000D, 0),
406f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, E000E, 0),
407f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, E000F, 0),
408f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, E0010, 0),
409f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, E0011, 0),
410f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, E0012, 0),
411f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, E0013, 0),
412f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, E0014, 0),
413f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, E0017, 0),
414f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, E0018, 0),
415f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, E0019, 0),
416f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, E0020, 0),
417f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, E0021, 0),
418f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, E0022, 0),
419f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, E0023, 0),
420f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, E0024, 0),
421f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, E0025, 0),
422f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, E0026, 0),
423f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, E0027, 0),
424f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, E0028, 0),
425f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, E0029, 0),
426f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, E0030, 0),
427f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, E0032, 0),
428f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, E0033, 0),
429f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, E0037, 0),
430f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, E0039, 0),
431f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, E0042, 0),
432f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, E0043, 0),
433f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, E0048, 0),
434f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, E0049, 0),
435f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, E0051, 0),
436f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, E0052, 0),
437f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, E0054, 0),
438f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, E0055, 0),
439f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, E0057, 0),
440f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, E0058, 0),
441f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, E0059, 0),
442f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, E0060, 0),
443f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, E0061, 0),
444f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, E0062, 0),
445f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, E0063, 0),
446f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, E0064, 0),
447f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, E0066, 0),
448f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, E0069, 0),
449f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, E0070, 0),
450f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, E0073, 0),
451f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, E0076, 0),
452f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, E0078, 0),
453f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, E0082, 0),
454f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, E0086, 0),
455f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, SURFSTICK, 0),
456f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, E2002, 0),
457f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, E2003, 0),
458f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, K3772_Z, 0),
459f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, K3772_Z_INIT, U3GINIT_SCSIEJECT),
460f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, MF112, U3GINIT_ZTESTOR),
461f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, MF195E, 0),
462f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, MF195E_INIT, U3GINIT_SCSIEJECT),
463f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, MF626, 0),
464f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, MF628, 0),
465f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, MF633R, 0),
466f9f848faSopenharmony_ci	/* the following is a RNDIS device, no modem features */
467f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, ZTE_MF730M, U3GINIT_SCSIEJECT),
468f9f848faSopenharmony_ci	U3G_DEV(QUANTA, GKE, 0),
469f9f848faSopenharmony_ci	U3G_DEV(QUANTA, GLE, 0),
470f9f848faSopenharmony_ci	U3G_DEV(QUANTA, GLX, 0),
471f9f848faSopenharmony_ci	U3G_DEV(QUANTA, Q101, 0),
472f9f848faSopenharmony_ci	U3G_DEV(QUANTA, Q111, 0),
473f9f848faSopenharmony_ci	U3G_DEV(QUECTEL, EC25, 0),
474f9f848faSopenharmony_ci	U3G_DEV(QUECTEL, EC200T, 0),
475f9f848faSopenharmony_ci	U3G_DEV(SIERRA, AC402, 0),
476f9f848faSopenharmony_ci	U3G_DEV(SIERRA, AC595U, 0),
477f9f848faSopenharmony_ci	U3G_DEV(SIERRA, AC313U, 0),
478f9f848faSopenharmony_ci	U3G_DEV(SIERRA, AC597E, 0),
479f9f848faSopenharmony_ci	U3G_DEV(SIERRA, AC875, 0),
480f9f848faSopenharmony_ci	U3G_DEV(SIERRA, AC875E, 0),
481f9f848faSopenharmony_ci	U3G_DEV(SIERRA, AC875U, 0),
482f9f848faSopenharmony_ci	U3G_DEV(SIERRA, AC875U_2, 0),
483f9f848faSopenharmony_ci	U3G_DEV(SIERRA, AC880, 0),
484f9f848faSopenharmony_ci	U3G_DEV(SIERRA, AC880E, 0),
485f9f848faSopenharmony_ci	U3G_DEV(SIERRA, AC880U, 0),
486f9f848faSopenharmony_ci	U3G_DEV(SIERRA, AC881, 0),
487f9f848faSopenharmony_ci	U3G_DEV(SIERRA, AC881E, 0),
488f9f848faSopenharmony_ci	U3G_DEV(SIERRA, AC881U, 0),
489f9f848faSopenharmony_ci	U3G_DEV(SIERRA, AC885E, 0),
490f9f848faSopenharmony_ci	U3G_DEV(SIERRA, AC885E_2, 0),
491f9f848faSopenharmony_ci	U3G_DEV(SIERRA, AC885U, 0),
492f9f848faSopenharmony_ci	U3G_DEV(SIERRA, AIRCARD580, 0),
493f9f848faSopenharmony_ci	U3G_DEV(SIERRA, AIRCARD595, 0),
494f9f848faSopenharmony_ci	U3G_DEV(SIERRA, C22, 0),
495f9f848faSopenharmony_ci	U3G_DEV(SIERRA, C597, 0),
496f9f848faSopenharmony_ci	U3G_DEV(SIERRA, C888, 0),
497f9f848faSopenharmony_ci	U3G_DEV(SIERRA, E0029, 0),
498f9f848faSopenharmony_ci	U3G_DEV(SIERRA, E6892, 0),
499f9f848faSopenharmony_ci	U3G_DEV(SIERRA, E6893, 0),
500f9f848faSopenharmony_ci	U3G_DEV(SIERRA, EM5625, 0),
501f9f848faSopenharmony_ci	U3G_DEV(SIERRA, EM5725, 0),
502f9f848faSopenharmony_ci	U3G_DEV(SIERRA, MC5720, 0),
503f9f848faSopenharmony_ci	U3G_DEV(SIERRA, MC5720_2, 0),
504f9f848faSopenharmony_ci	U3G_DEV(SIERRA, MC5725, 0),
505f9f848faSopenharmony_ci	U3G_DEV(SIERRA, MC5727, 0),
506f9f848faSopenharmony_ci	U3G_DEV(SIERRA, MC5727_2, 0),
507f9f848faSopenharmony_ci	U3G_DEV(SIERRA, MC5728, 0),
508f9f848faSopenharmony_ci	U3G_DEV(SIERRA, MC7354, 0),
509f9f848faSopenharmony_ci	U3G_DEV(SIERRA, MC7355, 0),
510f9f848faSopenharmony_ci	U3G_DEV(SIERRA, MC7430, 0),
511f9f848faSopenharmony_ci	U3G_DEV(SIERRA, MC8700, 0),
512f9f848faSopenharmony_ci	U3G_DEV(SIERRA, MC8755, 0),
513f9f848faSopenharmony_ci	U3G_DEV(SIERRA, MC8755_2, 0),
514f9f848faSopenharmony_ci	U3G_DEV(SIERRA, MC8755_3, 0),
515f9f848faSopenharmony_ci	U3G_DEV(SIERRA, MC8755_4, 0),
516f9f848faSopenharmony_ci	U3G_DEV(SIERRA, MC8765, 0),
517f9f848faSopenharmony_ci	U3G_DEV(SIERRA, MC8765_2, 0),
518f9f848faSopenharmony_ci	U3G_DEV(SIERRA, MC8765_3, 0),
519f9f848faSopenharmony_ci	U3G_DEV(SIERRA, MC8775, 0),
520f9f848faSopenharmony_ci	U3G_DEV(SIERRA, MC8775_2, 0),
521f9f848faSopenharmony_ci	U3G_DEV(SIERRA, MC8780, 0),
522f9f848faSopenharmony_ci	U3G_DEV(SIERRA, MC8780_2, 0),
523f9f848faSopenharmony_ci	U3G_DEV(SIERRA, MC8780_3, 0),
524f9f848faSopenharmony_ci	U3G_DEV(SIERRA, MC8781, 0),
525f9f848faSopenharmony_ci	U3G_DEV(SIERRA, MC8781_2, 0),
526f9f848faSopenharmony_ci	U3G_DEV(SIERRA, MC8781_3, 0),
527f9f848faSopenharmony_ci	U3G_DEV(SIERRA, MC8785, 0),
528f9f848faSopenharmony_ci	U3G_DEV(SIERRA, MC8785_2, 0),
529f9f848faSopenharmony_ci	U3G_DEV(SIERRA, MC8790, 0),
530f9f848faSopenharmony_ci	U3G_DEV(SIERRA, MC8791, 0),
531f9f848faSopenharmony_ci	U3G_DEV(SIERRA, MC8792, 0),
532f9f848faSopenharmony_ci	U3G_DEV(SIERRA, MINI5725, 0),
533f9f848faSopenharmony_ci	U3G_DEV(SIERRA, T11, 0),
534f9f848faSopenharmony_ci	U3G_DEV(SIERRA, T598, 0),
535f9f848faSopenharmony_ci	U3G_DEV(SILABS, SAEL, U3GINIT_SAEL_M460),
536f9f848faSopenharmony_ci	U3G_DEV(STELERA, C105, 0),
537f9f848faSopenharmony_ci	U3G_DEV(STELERA, E1003, 0),
538f9f848faSopenharmony_ci	U3G_DEV(STELERA, E1004, 0),
539f9f848faSopenharmony_ci	U3G_DEV(STELERA, E1005, 0),
540f9f848faSopenharmony_ci	U3G_DEV(STELERA, E1006, 0),
541f9f848faSopenharmony_ci	U3G_DEV(STELERA, E1007, 0),
542f9f848faSopenharmony_ci	U3G_DEV(STELERA, E1008, 0),
543f9f848faSopenharmony_ci	U3G_DEV(STELERA, E1009, 0),
544f9f848faSopenharmony_ci	U3G_DEV(STELERA, E100A, 0),
545f9f848faSopenharmony_ci	U3G_DEV(STELERA, E100B, 0),
546f9f848faSopenharmony_ci	U3G_DEV(STELERA, E100C, 0),
547f9f848faSopenharmony_ci	U3G_DEV(STELERA, E100D, 0),
548f9f848faSopenharmony_ci	U3G_DEV(STELERA, E100E, 0),
549f9f848faSopenharmony_ci	U3G_DEV(STELERA, E100F, 0),
550f9f848faSopenharmony_ci	U3G_DEV(STELERA, E1010, 0),
551f9f848faSopenharmony_ci	U3G_DEV(STELERA, E1011, 0),
552f9f848faSopenharmony_ci	U3G_DEV(STELERA, E1012, 0),
553f9f848faSopenharmony_ci	U3G_DEV(TCTMOBILE, X060S, 0),
554f9f848faSopenharmony_ci	U3G_DEV(TCTMOBILE, X080S, U3GINIT_TCT),
555f9f848faSopenharmony_ci	U3G_DEV(TELIT, UC864E, 0),
556f9f848faSopenharmony_ci	U3G_DEV(TELIT, UC864G, 0),
557f9f848faSopenharmony_ci	U3G_DEV(TLAYTECH, TEU800, 0),
558f9f848faSopenharmony_ci	U3G_DEV(TOSHIBA, G450, 0),
559f9f848faSopenharmony_ci	U3G_DEV(TOSHIBA, HSDPA, 0),
560f9f848faSopenharmony_ci	U3G_DEV(YISO, C893, 0),
561f9f848faSopenharmony_ci	U3G_DEV(WETELECOM, WM_D200, 0),
562f9f848faSopenharmony_ci	/* Autoinstallers */
563f9f848faSopenharmony_ci	U3G_DEV(NOVATEL, ZEROCD, U3GINIT_SCSIEJECT),
564f9f848faSopenharmony_ci	U3G_DEV(OPTION, GTICON322, U3GINIT_REZERO),
565f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, ZTE_STOR, U3GINIT_ZTESTOR),
566f9f848faSopenharmony_ci	U3G_DEV(QUALCOMMINC, ZTE_STOR2, U3GINIT_SCSIEJECT),
567f9f848faSopenharmony_ci	U3G_DEV(QUANTA, Q101_STOR, U3GINIT_SCSIEJECT),
568f9f848faSopenharmony_ci	U3G_DEV(SIERRA, TRUINSTALL, U3GINIT_SIERRA),
569f9f848faSopenharmony_ci#undef	U3G_DEV
570f9f848faSopenharmony_ci};
571f9f848faSopenharmony_ci
572f9f848faSopenharmony_cistatic void
573f9f848faSopenharmony_ciu3g_sael_m460_init(struct usb_device *udev)
574f9f848faSopenharmony_ci{
575f9f848faSopenharmony_ci	static const uint8_t setup[][24] = {
576f9f848faSopenharmony_ci	     { 0x41, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
577f9f848faSopenharmony_ci	     { 0x41, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00 },
578f9f848faSopenharmony_ci	     { 0x41, 0x13, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
579f9f848faSopenharmony_ci	       0x01, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
580f9f848faSopenharmony_ci	       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
581f9f848faSopenharmony_ci	     { 0xc1, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x40, 0x02 },
582f9f848faSopenharmony_ci	     { 0xc1, 0x08, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00 },
583f9f848faSopenharmony_ci	     { 0x41, 0x07, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00 },
584f9f848faSopenharmony_ci	     { 0xc1, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 },
585f9f848faSopenharmony_ci	     { 0x41, 0x01, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00 },
586f9f848faSopenharmony_ci	     { 0x41, 0x07, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00 },
587f9f848faSopenharmony_ci	     { 0x41, 0x03, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00 },
588f9f848faSopenharmony_ci	     { 0x41, 0x19, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00,
589f9f848faSopenharmony_ci	       0x00, 0x00, 0x00, 0x00, 0x11, 0x13 },
590f9f848faSopenharmony_ci	     { 0x41, 0x13, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
591f9f848faSopenharmony_ci	       0x09, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00,
592f9f848faSopenharmony_ci	       0x0a, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00 },
593f9f848faSopenharmony_ci	     { 0x41, 0x12, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00 },
594f9f848faSopenharmony_ci	     { 0x41, 0x01, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00 },
595f9f848faSopenharmony_ci	     { 0x41, 0x07, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00 },
596f9f848faSopenharmony_ci	     { 0x41, 0x03, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00 },
597f9f848faSopenharmony_ci	     { 0x41, 0x19, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00,
598f9f848faSopenharmony_ci	       0x00, 0x00, 0x00, 0x00, 0x11, 0x13 },
599f9f848faSopenharmony_ci	     { 0x41, 0x13, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
600f9f848faSopenharmony_ci	       0x09, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00,
601f9f848faSopenharmony_ci	       0x0a, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00 },
602f9f848faSopenharmony_ci	     { 0x41, 0x07, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00 },
603f9f848faSopenharmony_ci	};
604f9f848faSopenharmony_ci
605f9f848faSopenharmony_ci	struct usb_device_request req;
606f9f848faSopenharmony_ci	usb_error_t err;
607f9f848faSopenharmony_ci	uint16_t len;
608f9f848faSopenharmony_ci	uint8_t buf[0x300];
609f9f848faSopenharmony_ci	uint8_t n;
610f9f848faSopenharmony_ci
611f9f848faSopenharmony_ci	DPRINTFN(1, "\n");
612f9f848faSopenharmony_ci
613f9f848faSopenharmony_ci	if (usbd_req_set_alt_interface_no(udev, NULL, 0, 0)) {
614f9f848faSopenharmony_ci		DPRINTFN(0, "Alt setting 0 failed\n");
615f9f848faSopenharmony_ci		return;
616f9f848faSopenharmony_ci	}
617f9f848faSopenharmony_ci
618f9f848faSopenharmony_ci	for (n = 0; n != (sizeof(setup) / sizeof(setup[0])); n++) {
619f9f848faSopenharmony_ci		(void)memcpy_s(&req, sizeof(req), setup[n], sizeof(req));
620f9f848faSopenharmony_ci
621f9f848faSopenharmony_ci		len = UGETW(req.wLength);
622f9f848faSopenharmony_ci		if (req.bmRequestType & UE_DIR_IN) {
623f9f848faSopenharmony_ci			if (len > sizeof(buf)) {
624f9f848faSopenharmony_ci				DPRINTFN(0, "too small buffer\n");
625f9f848faSopenharmony_ci				continue;
626f9f848faSopenharmony_ci			}
627f9f848faSopenharmony_ci			err = usbd_do_request(udev, NULL, &req, buf);
628f9f848faSopenharmony_ci		} else {
629f9f848faSopenharmony_ci			if (len > (sizeof(setup[0]) - 8)) {
630f9f848faSopenharmony_ci				DPRINTFN(0, "too small buffer\n");
631f9f848faSopenharmony_ci				continue;
632f9f848faSopenharmony_ci			}
633f9f848faSopenharmony_ci			err = usbd_do_request(udev, NULL, &req,
634f9f848faSopenharmony_ci			    __DECONST(uint8_t *, &setup[n][8]));
635f9f848faSopenharmony_ci		}
636f9f848faSopenharmony_ci		if (err) {
637f9f848faSopenharmony_ci			DPRINTFN(1, "request %u failed\n",
638f9f848faSopenharmony_ci			    (unsigned int)n);
639f9f848faSopenharmony_ci			/*
640f9f848faSopenharmony_ci			 * Some of the requests will fail. Stop doing
641f9f848faSopenharmony_ci			 * requests when we are getting timeouts so
642f9f848faSopenharmony_ci			 * that we don't block the explore/attach
643f9f848faSopenharmony_ci			 * thread forever.
644f9f848faSopenharmony_ci			 */
645f9f848faSopenharmony_ci			if (err == USB_ERR_TIMEOUT)
646f9f848faSopenharmony_ci				break;
647f9f848faSopenharmony_ci		}
648f9f848faSopenharmony_ci	}
649f9f848faSopenharmony_ci}
650f9f848faSopenharmony_ci
651f9f848faSopenharmony_cistatic int
652f9f848faSopenharmony_ciu3g_probe(device_t self)
653f9f848faSopenharmony_ci{
654f9f848faSopenharmony_ci	struct usb_attach_arg *uaa = (struct usb_attach_arg *)device_get_ivars(self);
655f9f848faSopenharmony_ci
656f9f848faSopenharmony_ci	if (uaa->usb_mode != USB_MODE_HOST) {
657f9f848faSopenharmony_ci		return (ENXIO);
658f9f848faSopenharmony_ci	}
659f9f848faSopenharmony_ci
660f9f848faSopenharmony_ci	if (uaa->info.bInterfaceClass != UICLASS_VENDOR) {
661f9f848faSopenharmony_ci		return (ENXIO);
662f9f848faSopenharmony_ci	}
663f9f848faSopenharmony_ci	return (usbd_lookup_id_by_uaa(u3g_devs, sizeof(u3g_devs), uaa));
664f9f848faSopenharmony_ci}
665f9f848faSopenharmony_ci
666f9f848faSopenharmony_cistatic int
667f9f848faSopenharmony_ciu3g_attach(device_t dev)
668f9f848faSopenharmony_ci{
669f9f848faSopenharmony_ci	struct usb_config u3g_config_tmp[U3G_N_TRANSFER];
670f9f848faSopenharmony_ci	struct usb_attach_arg *uaa = (struct usb_attach_arg *)device_get_ivars(dev);
671f9f848faSopenharmony_ci	struct u3g_softc *sc = (struct u3g_softc *)device_get_softc(dev);
672f9f848faSopenharmony_ci	struct usb_interface *iface;
673f9f848faSopenharmony_ci	struct usb_interface_descriptor *id;
674f9f848faSopenharmony_ci	uint32_t iface_valid;
675f9f848faSopenharmony_ci	int error, type, nports;
676f9f848faSopenharmony_ci	int ep, n;
677f9f848faSopenharmony_ci	uint8_t i;
678f9f848faSopenharmony_ci
679f9f848faSopenharmony_ci	DPRINTF("sc=%p\n", sc);
680f9f848faSopenharmony_ci
681f9f848faSopenharmony_ci	type = USB_GET_DRIVER_INFO(uaa);
682f9f848faSopenharmony_ci	if (type == U3GINIT_SAEL_M460
683f9f848faSopenharmony_ci		|| usb_test_quirk(uaa, UQ_MSC_EJECT_SAEL_M460)) {
684f9f848faSopenharmony_ci		u3g_sael_m460_init(uaa->device);
685f9f848faSopenharmony_ci	}
686f9f848faSopenharmony_ci
687f9f848faSopenharmony_ci	/* copy in USB config */
688f9f848faSopenharmony_ci	for (n = 0; n != U3G_N_TRANSFER; n++)
689f9f848faSopenharmony_ci		u3g_config_tmp[n] = u3g_config[n];
690f9f848faSopenharmony_ci
691f9f848faSopenharmony_ci	device_set_usb_desc(dev);
692f9f848faSopenharmony_ci	mtx_init(&sc->sc_mtx, "u3g", NULL, MTX_DEF);
693f9f848faSopenharmony_ci	ucom_ref(&sc->sc_super_ucom);
694f9f848faSopenharmony_ci
695f9f848faSopenharmony_ci	sc->sc_udev = uaa->device;
696f9f848faSopenharmony_ci
697f9f848faSopenharmony_ci	/* Claim all interfaces on the device */
698f9f848faSopenharmony_ci	iface_valid = 0;
699f9f848faSopenharmony_ci	for (i = uaa->info.bIfaceIndex; i < USB_IFACE_MAX; i++) {
700f9f848faSopenharmony_ci		iface = usbd_get_iface(uaa->device, i);
701f9f848faSopenharmony_ci		if (iface == NULL)
702f9f848faSopenharmony_ci			break;
703f9f848faSopenharmony_ci		id = usbd_get_interface_descriptor(iface);
704f9f848faSopenharmony_ci		if (id == NULL || id->bInterfaceClass != UICLASS_VENDOR)
705f9f848faSopenharmony_ci			continue;
706f9f848faSopenharmony_ci		usbd_set_parent_iface(uaa->device, i, uaa->info.bIfaceIndex);
707f9f848faSopenharmony_ci		iface_valid |= (1<<i);
708f9f848faSopenharmony_ci	}
709f9f848faSopenharmony_ci
710f9f848faSopenharmony_ci	i = 0;		/* interface index */
711f9f848faSopenharmony_ci	ep = 0;		/* endpoint index */
712f9f848faSopenharmony_ci	nports = 0;	/* number of ports */
713f9f848faSopenharmony_ci	while (i < USB_IFACE_MAX) {
714f9f848faSopenharmony_ci		if ((iface_valid & (1<<i)) == 0) {
715f9f848faSopenharmony_ci			i++;
716f9f848faSopenharmony_ci			continue;
717f9f848faSopenharmony_ci		}
718f9f848faSopenharmony_ci
719f9f848faSopenharmony_ci		/* update BULK endpoint index */
720f9f848faSopenharmony_ci		for (n = 0; n < U3G_N_TRANSFER; n++)
721f9f848faSopenharmony_ci			u3g_config_tmp[n].ep_index = ep;
722f9f848faSopenharmony_ci
723f9f848faSopenharmony_ci		/* try to allocate a set of BULK endpoints */
724f9f848faSopenharmony_ci		error = usbd_transfer_setup(uaa->device, &i,
725f9f848faSopenharmony_ci		    sc->sc_xfer[nports], u3g_config_tmp, U3G_N_TRANSFER,
726f9f848faSopenharmony_ci		    &sc->sc_ucom[nports], &sc->sc_mtx);
727f9f848faSopenharmony_ci		if (error) {
728f9f848faSopenharmony_ci			/* next interface */
729f9f848faSopenharmony_ci			i++;
730f9f848faSopenharmony_ci			ep = 0;
731f9f848faSopenharmony_ci			continue;
732f9f848faSopenharmony_ci		}
733f9f848faSopenharmony_ci
734f9f848faSopenharmony_ci		iface = usbd_get_iface(uaa->device, i);
735f9f848faSopenharmony_ci		id = usbd_get_interface_descriptor(iface);
736f9f848faSopenharmony_ci		sc->sc_iface[nports] = id->bInterfaceNumber;
737f9f848faSopenharmony_ci
738f9f848faSopenharmony_ci		nports++;	/* found one port */
739f9f848faSopenharmony_ci		ep++;
740f9f848faSopenharmony_ci		if (nports == U3G_MAXPORTS)
741f9f848faSopenharmony_ci			break;
742f9f848faSopenharmony_ci	}
743f9f848faSopenharmony_ci	if (nports == 0) {
744f9f848faSopenharmony_ci		device_printf(dev, "no ports found\n");
745f9f848faSopenharmony_ci		goto detach;
746f9f848faSopenharmony_ci	}
747f9f848faSopenharmony_ci	sc->sc_numports = nports;
748f9f848faSopenharmony_ci
749f9f848faSopenharmony_ci	error = ucom_attach(&sc->sc_super_ucom, sc->sc_ucom,
750f9f848faSopenharmony_ci		sc->sc_numports, sc, &u3g_callback, &sc->sc_mtx);
751f9f848faSopenharmony_ci	if (error) {
752f9f848faSopenharmony_ci		DPRINTF("ucom_attach failed\n");
753f9f848faSopenharmony_ci		goto detach;
754f9f848faSopenharmony_ci	}
755f9f848faSopenharmony_ci
756f9f848faSopenharmony_ci	ucom_set_pnpinfo_usb(&sc->sc_super_ucom, dev);
757f9f848faSopenharmony_ci	device_printf(dev, "Found %u port%s.\n", sc->sc_numports,
758f9f848faSopenharmony_ci	    sc->sc_numports > 1 ? "s":"");
759f9f848faSopenharmony_ci
760f9f848faSopenharmony_ci	return (0);
761f9f848faSopenharmony_ci
762f9f848faSopenharmony_cidetach:
763f9f848faSopenharmony_ci	(void)u3g_detach(dev);
764f9f848faSopenharmony_ci	return (ENXIO);
765f9f848faSopenharmony_ci}
766f9f848faSopenharmony_ci
767f9f848faSopenharmony_cistatic int
768f9f848faSopenharmony_ciu3g_detach(device_t dev)
769f9f848faSopenharmony_ci{
770f9f848faSopenharmony_ci	struct u3g_softc *sc = (struct u3g_softc *)device_get_softc(dev);
771f9f848faSopenharmony_ci	uint8_t subunit;
772f9f848faSopenharmony_ci
773f9f848faSopenharmony_ci	DPRINTF("sc=%p\n", sc);
774f9f848faSopenharmony_ci
775f9f848faSopenharmony_ci	/* NOTE: It is not dangerous to detach more ports than attached! */
776f9f848faSopenharmony_ci	ucom_detach(&sc->sc_super_ucom, sc->sc_ucom);
777f9f848faSopenharmony_ci
778f9f848faSopenharmony_ci	for (subunit = 0; subunit != U3G_MAXPORTS; subunit++)
779f9f848faSopenharmony_ci		usbd_transfer_unsetup(sc->sc_xfer[subunit], U3G_N_TRANSFER);
780f9f848faSopenharmony_ci
781f9f848faSopenharmony_ci	if (ucom_unref(&sc->sc_super_ucom)) {
782f9f848faSopenharmony_ci		mtx_destroy(&sc->sc_mtx);
783f9f848faSopenharmony_ci	}
784f9f848faSopenharmony_ci
785f9f848faSopenharmony_ci	return (0);
786f9f848faSopenharmony_ci}
787f9f848faSopenharmony_ci
788f9f848faSopenharmony_cistatic void
789f9f848faSopenharmony_ciu3g_free_softc(struct u3g_softc *sc)
790f9f848faSopenharmony_ci{
791f9f848faSopenharmony_ci	if (ucom_unref(&sc->sc_super_ucom)) {
792f9f848faSopenharmony_ci		mtx_destroy(&sc->sc_mtx);
793f9f848faSopenharmony_ci		free(sc);
794f9f848faSopenharmony_ci	}
795f9f848faSopenharmony_ci}
796f9f848faSopenharmony_ci
797f9f848faSopenharmony_cistatic void
798f9f848faSopenharmony_ciu3g_free(struct ucom_softc *ucom)
799f9f848faSopenharmony_ci{
800f9f848faSopenharmony_ci	u3g_free_softc((struct u3g_softc *)ucom->sc_parent);
801f9f848faSopenharmony_ci}
802f9f848faSopenharmony_ci
803f9f848faSopenharmony_cistatic void
804f9f848faSopenharmony_ciu3g_start_read(struct ucom_softc *ucom)
805f9f848faSopenharmony_ci{
806f9f848faSopenharmony_ci	struct u3g_softc *sc = (struct u3g_softc *)ucom->sc_parent;
807f9f848faSopenharmony_ci
808f9f848faSopenharmony_ci	/* start interrupt endpoint (if configured) */
809f9f848faSopenharmony_ci	usbd_transfer_start(sc->sc_xfer[ucom->sc_subunit][U3G_INTR]);
810f9f848faSopenharmony_ci
811f9f848faSopenharmony_ci	/* start read endpoint */
812f9f848faSopenharmony_ci	usbd_transfer_start(sc->sc_xfer[ucom->sc_subunit][U3G_BULK_RD]);
813f9f848faSopenharmony_ci}
814f9f848faSopenharmony_ci
815f9f848faSopenharmony_cistatic void
816f9f848faSopenharmony_ciu3g_stop_read(struct ucom_softc *ucom)
817f9f848faSopenharmony_ci{
818f9f848faSopenharmony_ci	struct u3g_softc *sc = (struct u3g_softc *)ucom->sc_parent;
819f9f848faSopenharmony_ci
820f9f848faSopenharmony_ci	/* stop interrupt endpoint (if configured) */
821f9f848faSopenharmony_ci	usbd_transfer_stop(sc->sc_xfer[ucom->sc_subunit][U3G_INTR]);
822f9f848faSopenharmony_ci
823f9f848faSopenharmony_ci	/* stop read endpoint */
824f9f848faSopenharmony_ci	usbd_transfer_stop(sc->sc_xfer[ucom->sc_subunit][U3G_BULK_RD]);
825f9f848faSopenharmony_ci}
826f9f848faSopenharmony_ci
827f9f848faSopenharmony_cistatic void
828f9f848faSopenharmony_ciu3g_start_write(struct ucom_softc *ucom)
829f9f848faSopenharmony_ci{
830f9f848faSopenharmony_ci	struct u3g_softc *sc = (struct u3g_softc *)ucom->sc_parent;
831f9f848faSopenharmony_ci
832f9f848faSopenharmony_ci	usbd_transfer_start(sc->sc_xfer[ucom->sc_subunit][U3G_BULK_WR]);
833f9f848faSopenharmony_ci}
834f9f848faSopenharmony_ci
835f9f848faSopenharmony_cistatic void
836f9f848faSopenharmony_ciu3g_stop_write(struct ucom_softc *ucom)
837f9f848faSopenharmony_ci{
838f9f848faSopenharmony_ci	struct u3g_softc *sc = (struct u3g_softc *)ucom->sc_parent;
839f9f848faSopenharmony_ci
840f9f848faSopenharmony_ci	usbd_transfer_stop(sc->sc_xfer[ucom->sc_subunit][U3G_BULK_WR]);
841f9f848faSopenharmony_ci}
842f9f848faSopenharmony_ci
843f9f848faSopenharmony_cistatic void
844f9f848faSopenharmony_ciu3g_write_callback(struct usb_xfer *xfer, usb_error_t error)
845f9f848faSopenharmony_ci{
846f9f848faSopenharmony_ci	struct ucom_softc *ucom = (struct ucom_softc *)usbd_xfer_softc(xfer);
847f9f848faSopenharmony_ci	struct usb_page_cache *pc;
848f9f848faSopenharmony_ci	uint32_t actlen;
849f9f848faSopenharmony_ci	uint32_t frame;
850f9f848faSopenharmony_ci
851f9f848faSopenharmony_ci	ucom_handler_item_s *p_u3g_write_handler;
852f9f848faSopenharmony_ci	static uint32_t writelen;
853f9f848faSopenharmony_ci
854f9f848faSopenharmony_ci	DPRINTFN(1, "\n");
855f9f848faSopenharmony_ci
856f9f848faSopenharmony_ci	switch (USB_GET_STATE(xfer)) {
857f9f848faSopenharmony_ci	case USB_ST_TRANSFERRED:
858f9f848faSopenharmony_ci
859f9f848faSopenharmony_ci		p_u3g_write_handler = (ucom_handler_item_s *)LOS_MemboxAlloc(m_auc_tty_usb_handler_pool);
860f9f848faSopenharmony_ci		if (p_u3g_write_handler != NULL) {
861f9f848faSopenharmony_ci			p_u3g_write_handler->length = writelen;
862f9f848faSopenharmony_ci			if (LOS_QueueWrite(m_uw_tty_usb_handler_queue, p_u3g_write_handler,
863f9f848faSopenharmony_ci							    sizeof(UINT32), LOS_NO_WAIT)) {
864f9f848faSopenharmony_ci				(VOID)LOS_MemboxFree(m_auc_tty_usb_handler_pool, p_u3g_write_handler);
865f9f848faSopenharmony_ci			}
866f9f848faSopenharmony_ci		}
867f9f848faSopenharmony_ci
868f9f848faSopenharmony_ci	case USB_ST_SETUP:
869f9f848faSopenharmony_citr_setup:
870f9f848faSopenharmony_ci		for (frame = 0; frame != U3G_TXFRAMES; frame++) {
871f9f848faSopenharmony_ci			usbd_xfer_set_frame_offset(xfer, frame * U3G_TXSIZE, frame);
872f9f848faSopenharmony_ci
873f9f848faSopenharmony_ci			pc = usbd_xfer_get_frame(xfer, frame);
874f9f848faSopenharmony_ci			if (ucom_get_data(ucom, pc, 0, U3G_TXSIZE, &actlen) == 0)
875f9f848faSopenharmony_ci				break;
876f9f848faSopenharmony_ci
877f9f848faSopenharmony_ci			usbd_xfer_set_frame_len(xfer, frame, actlen);
878f9f848faSopenharmony_ci			writelen = actlen;
879f9f848faSopenharmony_ci		}
880f9f848faSopenharmony_ci		if (frame != 0) {
881f9f848faSopenharmony_ci			usbd_xfer_set_frames(xfer, frame);
882f9f848faSopenharmony_ci			usbd_transfer_submit(xfer);
883f9f848faSopenharmony_ci		}
884f9f848faSopenharmony_ci		break;
885f9f848faSopenharmony_ci
886f9f848faSopenharmony_ci	default:			/* Error */
887f9f848faSopenharmony_ci		if (error != USB_ERR_CANCELLED) {
888f9f848faSopenharmony_ci			/* do a builtin clear-stall */
889f9f848faSopenharmony_ci			usbd_xfer_set_stall(xfer);
890f9f848faSopenharmony_ci			goto tr_setup;
891f9f848faSopenharmony_ci		}
892f9f848faSopenharmony_ci		break;
893f9f848faSopenharmony_ci	}
894f9f848faSopenharmony_ci}
895f9f848faSopenharmony_ci
896f9f848faSopenharmony_cistatic void
897f9f848faSopenharmony_ciu3g_read_callback(struct usb_xfer *xfer, usb_error_t error)
898f9f848faSopenharmony_ci{
899f9f848faSopenharmony_ci	struct ucom_softc *ucom = (struct ucom_softc *)usbd_xfer_softc(xfer);
900f9f848faSopenharmony_ci	struct usb_page_cache *pc;
901f9f848faSopenharmony_ci	int actlen;
902f9f848faSopenharmony_ci
903f9f848faSopenharmony_ci	DPRINTFN(1, "\n");
904f9f848faSopenharmony_ci
905f9f848faSopenharmony_ci	usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
906f9f848faSopenharmony_ci
907f9f848faSopenharmony_ci	switch (USB_GET_STATE(xfer)) {
908f9f848faSopenharmony_ci	case USB_ST_TRANSFERRED:
909f9f848faSopenharmony_ci		pc = usbd_xfer_get_frame(xfer, 0);
910f9f848faSopenharmony_ci		ucom_put_data(ucom, pc, 0, actlen);
911f9f848faSopenharmony_ci
912f9f848faSopenharmony_ci	case USB_ST_SETUP:
913f9f848faSopenharmony_citr_setup:
914f9f848faSopenharmony_ci		usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer));
915f9f848faSopenharmony_ci		usbd_transfer_submit(xfer);
916f9f848faSopenharmony_ci		break;
917f9f848faSopenharmony_ci
918f9f848faSopenharmony_ci	default:			/* Error */
919f9f848faSopenharmony_ci		if (error != USB_ERR_CANCELLED) {
920f9f848faSopenharmony_ci			/* do a builtin clear-stall */
921f9f848faSopenharmony_ci			usbd_xfer_set_stall(xfer);
922f9f848faSopenharmony_ci			goto tr_setup;
923f9f848faSopenharmony_ci		}
924f9f848faSopenharmony_ci		break;
925f9f848faSopenharmony_ci	}
926f9f848faSopenharmony_ci}
927f9f848faSopenharmony_ci
928f9f848faSopenharmony_cistatic void
929f9f848faSopenharmony_ciu3g_cfg_get_status(struct ucom_softc *ucom, uint8_t *lsr, uint8_t *msr)
930f9f848faSopenharmony_ci{
931f9f848faSopenharmony_ci	struct u3g_softc *sc = (struct u3g_softc *)ucom->sc_parent;
932f9f848faSopenharmony_ci
933f9f848faSopenharmony_ci	*lsr = sc->sc_lsr[ucom->sc_subunit];
934f9f848faSopenharmony_ci	*msr = sc->sc_msr[ucom->sc_subunit];
935f9f848faSopenharmony_ci}
936f9f848faSopenharmony_ci
937f9f848faSopenharmony_cistatic void
938f9f848faSopenharmony_ciu3g_cfg_set_line(struct ucom_softc *ucom)
939f9f848faSopenharmony_ci{
940f9f848faSopenharmony_ci	struct u3g_softc *sc = (struct u3g_softc *)ucom->sc_parent;
941f9f848faSopenharmony_ci	struct usb_device_request req;
942f9f848faSopenharmony_ci
943f9f848faSopenharmony_ci	req.bmRequestType = UT_WRITE_CLASS_INTERFACE;
944f9f848faSopenharmony_ci	req.bRequest = UCDC_SET_CONTROL_LINE_STATE;
945f9f848faSopenharmony_ci	USETW(req.wValue, sc->sc_line[ucom->sc_subunit]);
946f9f848faSopenharmony_ci	req.wIndex[0] = sc->sc_iface[ucom->sc_subunit];
947f9f848faSopenharmony_ci	req.wIndex[1] = 0;
948f9f848faSopenharmony_ci	req.wLength[0] = 0;
949f9f848faSopenharmony_ci	req.wLength[1] = 0;
950f9f848faSopenharmony_ci
951f9f848faSopenharmony_ci	(void)ucom_cfg_do_request(sc->sc_udev, ucom,
952f9f848faSopenharmony_ci		&req, NULL, 0, 1000);
953f9f848faSopenharmony_ci}
954f9f848faSopenharmony_ci
955f9f848faSopenharmony_cistatic void
956f9f848faSopenharmony_ciu3g_cfg_set_dtr(struct ucom_softc *ucom, uint8_t onoff)
957f9f848faSopenharmony_ci{
958f9f848faSopenharmony_ci	struct u3g_softc *sc = (struct u3g_softc *)ucom->sc_parent;
959f9f848faSopenharmony_ci
960f9f848faSopenharmony_ci	DPRINTF("onoff = %d\n", onoff);
961f9f848faSopenharmony_ci
962f9f848faSopenharmony_ci	if (onoff)
963f9f848faSopenharmony_ci		sc->sc_line[ucom->sc_subunit] |= UCDC_LINE_DTR;
964f9f848faSopenharmony_ci	else
965f9f848faSopenharmony_ci		sc->sc_line[ucom->sc_subunit] &= ~UCDC_LINE_DTR;
966f9f848faSopenharmony_ci
967f9f848faSopenharmony_ci	u3g_cfg_set_line(ucom);
968f9f848faSopenharmony_ci}
969f9f848faSopenharmony_ci
970f9f848faSopenharmony_cistatic void
971f9f848faSopenharmony_ciu3g_cfg_set_rts(struct ucom_softc *ucom, uint8_t onoff)
972f9f848faSopenharmony_ci{
973f9f848faSopenharmony_ci	struct u3g_softc *sc = (struct u3g_softc *)ucom->sc_parent;
974f9f848faSopenharmony_ci
975f9f848faSopenharmony_ci	DPRINTF("onoff = %d\n", onoff);
976f9f848faSopenharmony_ci
977f9f848faSopenharmony_ci	if (onoff)
978f9f848faSopenharmony_ci		sc->sc_line[ucom->sc_subunit] |= UCDC_LINE_RTS;
979f9f848faSopenharmony_ci	else
980f9f848faSopenharmony_ci		sc->sc_line[ucom->sc_subunit] &= ~UCDC_LINE_RTS;
981f9f848faSopenharmony_ci
982f9f848faSopenharmony_ci	u3g_cfg_set_line(ucom);
983f9f848faSopenharmony_ci}
984f9f848faSopenharmony_ci
985f9f848faSopenharmony_cistatic void
986f9f848faSopenharmony_ciu3g_intr_callback(struct usb_xfer *xfer, usb_error_t error)
987f9f848faSopenharmony_ci{
988f9f848faSopenharmony_ci	struct ucom_softc *ucom = (struct ucom_softc *)usbd_xfer_softc(xfer);
989f9f848faSopenharmony_ci	struct u3g_softc *sc = (struct u3g_softc *)ucom->sc_parent;
990f9f848faSopenharmony_ci	struct usb_page_cache *pc;
991f9f848faSopenharmony_ci	struct usb_cdc_notification pkt;
992f9f848faSopenharmony_ci	int actlen;
993f9f848faSopenharmony_ci	uint16_t wLen;
994f9f848faSopenharmony_ci	uint8_t mstatus;
995f9f848faSopenharmony_ci	int i;
996f9f848faSopenharmony_ci
997f9f848faSopenharmony_ci	DPRINTFN(1, "\n");
998f9f848faSopenharmony_ci
999f9f848faSopenharmony_ci	usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
1000f9f848faSopenharmony_ci
1001f9f848faSopenharmony_ci	switch (USB_GET_STATE(xfer)) {
1002f9f848faSopenharmony_ci	case USB_ST_TRANSFERRED:
1003f9f848faSopenharmony_ci		if (actlen < 8) {	/* usb_cdc_notification with 2 data bytes */
1004f9f848faSopenharmony_ci			DPRINTF("message too short (expected 8, received %d)\n", actlen);
1005f9f848faSopenharmony_ci			goto tr_setup;
1006f9f848faSopenharmony_ci		}
1007f9f848faSopenharmony_ci		pc = usbd_xfer_get_frame(xfer, 0);
1008f9f848faSopenharmony_ci		usbd_copy_out(pc, 0, &pkt, actlen);
1009f9f848faSopenharmony_ci
1010f9f848faSopenharmony_ci		PRINTK("read intr data start -->\n\n");
1011f9f848faSopenharmony_ci		for (i=0; i<actlen; i++) {
1012f9f848faSopenharmony_ci			PRINTK("[0x%x]  ", *((char*)pc->buffer+i));
1013f9f848faSopenharmony_ci		}
1014f9f848faSopenharmony_ci		PRINTK("\nread intr data end -->\n\n");
1015f9f848faSopenharmony_ci
1016f9f848faSopenharmony_ci		wLen = UGETW(pkt.wLength);
1017f9f848faSopenharmony_ci		if (wLen < 2) {
1018f9f848faSopenharmony_ci			DPRINTF("message too short (expected 2 data bytes, received %d)\n", wLen);
1019f9f848faSopenharmony_ci			goto tr_setup;
1020f9f848faSopenharmony_ci		}
1021f9f848faSopenharmony_ci
1022f9f848faSopenharmony_ci		if (pkt.bmRequestType == UCDC_NOTIFICATION
1023f9f848faSopenharmony_ci		    && pkt.bNotification == UCDC_N_SERIAL_STATE) {
1024f9f848faSopenharmony_ci			/*
1025f9f848faSopenharmony_ci		     * Set the serial state in ucom driver based on
1026f9f848faSopenharmony_ci		     * the bits from the notify message
1027f9f848faSopenharmony_ci		     */
1028f9f848faSopenharmony_ci			DPRINTF("notify bytes = 0x%02x, 0x%02x\n",
1029f9f848faSopenharmony_ci			    pkt.data[0], pkt.data[1]);
1030f9f848faSopenharmony_ci
1031f9f848faSopenharmony_ci			/* currently, lsr is always zero. */
1032f9f848faSopenharmony_ci			sc->sc_lsr[ucom->sc_subunit] = 0;
1033f9f848faSopenharmony_ci			sc->sc_msr[ucom->sc_subunit] = 0;
1034f9f848faSopenharmony_ci
1035f9f848faSopenharmony_ci			mstatus = pkt.data[0];
1036f9f848faSopenharmony_ci
1037f9f848faSopenharmony_ci			if (mstatus & UCDC_N_SERIAL_RI)
1038f9f848faSopenharmony_ci				sc->sc_msr[ucom->sc_subunit] |= SER_RI;
1039f9f848faSopenharmony_ci			if (mstatus & UCDC_N_SERIAL_DSR)
1040f9f848faSopenharmony_ci				sc->sc_msr[ucom->sc_subunit] |= SER_DSR;
1041f9f848faSopenharmony_ci			if (mstatus & UCDC_N_SERIAL_DCD)
1042f9f848faSopenharmony_ci				sc->sc_msr[ucom->sc_subunit] |= SER_DCD;
1043f9f848faSopenharmony_ci			ucom_status_change(ucom);
1044f9f848faSopenharmony_ci		}
1045f9f848faSopenharmony_ci
1046f9f848faSopenharmony_ci	case USB_ST_SETUP:
1047f9f848faSopenharmony_citr_setup:
1048f9f848faSopenharmony_ci		usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer));
1049f9f848faSopenharmony_ci		usbd_transfer_submit(xfer);
1050f9f848faSopenharmony_ci		return;
1051f9f848faSopenharmony_ci
1052f9f848faSopenharmony_ci	default:			/* Error */
1053f9f848faSopenharmony_ci		if (error != USB_ERR_CANCELLED) {
1054f9f848faSopenharmony_ci			/* try to clear stall first */
1055f9f848faSopenharmony_ci			usbd_xfer_set_stall(xfer);
1056f9f848faSopenharmony_ci			goto tr_setup;
1057f9f848faSopenharmony_ci		}
1058f9f848faSopenharmony_ci		return;
1059f9f848faSopenharmony_ci	}
1060f9f848faSopenharmony_ci}
1061f9f848faSopenharmony_ci
1062f9f848faSopenharmony_cistatic void
1063f9f848faSopenharmony_ciu3g_poll(struct ucom_softc *ucom)
1064f9f848faSopenharmony_ci{
1065f9f848faSopenharmony_ci	struct u3g_softc *sc = (struct u3g_softc *)ucom->sc_parent;
1066f9f848faSopenharmony_ci	usbd_transfer_poll(sc->sc_xfer[ucom->sc_subunit], U3G_N_TRANSFER);
1067f9f848faSopenharmony_ci}
1068f9f848faSopenharmony_ci
1069f9f848faSopenharmony_ci#undef USB_DEBUG_VAR
1070