pl2303_var.h revision 903:a9ef93192894
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License").  You may not use this file except in compliance
7 * with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22/*
23 * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24 * Use is subject to license terms.
25 */
26
27#ifndef _SYS_USB_USBSER_PL2303_VAR_H
28#define	_SYS_USB_USBSER_PL2303_VAR_H
29
30#pragma ident	"%Z%%M%	%I%	%E% SMI"
31
32/*
33 * USB PL2303 definitions
34 */
35
36#include <sys/types.h>
37#include <sys/dditypes.h>
38#include <sys/note.h>
39
40#include <sys/usb/clients/usbser/usbser_dsdi.h>
41
42#ifdef	__cplusplus
43extern "C" {
44#endif
45
46/*
47 * PM support
48 */
49typedef struct pl2303_power {
50	uint8_t		pm_wakeup_enabled;	/* remote wakeup enabled */
51	uint8_t		pm_pwr_states;	/* bit mask of power states */
52	boolean_t	pm_raise_power;	/* driver is about to raise power */
53	uint8_t		pm_cur_power;	/* current power level */
54	uint_t		pm_busy_cnt;	/* number of set_busy requests */
55} pl2303_pm_t;
56
57
58/*
59 * From device driver's perspective, there is no difference
60 * between PL-2303HX and PL-2303X chips, so pl2303_X will
61 * stand for two chiptypes
62 */
63enum pl2303_chip {
64	pl2303_H,		/* PL-2303H chip */
65	pl2303_X,		/* PL-2303HX and PL-2303X chip */
66	pl2303_UNKNOWN		/* Unkown chip type */
67};
68
69/*
70 * per device state structure
71 */
72typedef struct pl2303_state {
73	kmutex_t		pl_mutex;		/* structure lock */
74	dev_info_t		*pl_dip;		/* device info */
75	int			pl_dev_flags;		/* device flags */
76	int			pl_port_state;		/* port state */
77	int			pl_port_flags;		/* port flags */
78	ds_cb_t			pl_cb;			/* DSD callbacks */
79	/*
80	 * USBA
81	 */
82	usb_client_dev_data_t	*pl_dev_data;		/* registration data */
83	usb_event_t		*pl_usb_events;		/* usb events */
84	usb_pipe_handle_t	pl_def_ph;		/* default pipe hdl */
85	usb_pipe_handle_t	pl_bulkin_ph;		/* in pipe hdl */
86	int			pl_bulkin_state;	/* in pipe state */
87	usb_pipe_handle_t	pl_bulkout_ph;		/* in pipe hdl */
88	int			pl_bulkout_state;	/* out pipe state */
89	usb_log_handle_t	pl_lh;			/* USBA log handle */
90	int			pl_dev_state;		/* USB device state */
91	size_t			pl_xfer_sz;		/* HCI bulk xfer size */
92	pl2303_pm_t		*pl_pm;			/* PM support */
93	/*
94	 * data receipt and transmit
95	 */
96	mblk_t			*pl_rx_mp;		/* rx data */
97	mblk_t			*pl_tx_mp;		/* tx data */
98	kcondvar_t		pl_tx_cv;		/* tx completion */
99	kcondvar_t		pl_rx_cv;		/* rx completion */
100	/*
101	 * other
102	 */
103	uint8_t			pl_mctl;		/* modem controls */
104	enum pl2303_chip	pl_chiptype;		/* chip type */
105} pl2303_state_t;
106
107_NOTE(MUTEX_PROTECTS_DATA(pl2303_state::pl_mutex, pl2303_state))
108_NOTE(DATA_READABLE_WITHOUT_LOCK(pl2303_state::{
109	pl_dip
110	pl_dev_data
111	pl_usb_events
112	pl_def_ph
113	pl_lh
114	pl_xfer_sz
115	pl_pm
116	pl_port_state
117	pl_cb.cb_rx
118	pl_cb.cb_tx
119	pl_cb.cb_arg
120	pl_bulkin_ph
121	pl_bulkout_ph
122	pl_chiptype
123}))
124
125
126/* port state */
127enum {
128	PL2303_PORT_CLOSED,			/* port is closed */
129	PL2303_PORT_OPEN,			/* port is open */
130	PL2303_PORT_CLOSING
131};
132
133/* port flags */
134enum {
135	PL2303_PORT_TX_STOPPED	= 0x0001	/* transmit not allowed */
136};
137
138/* pipe state */
139enum {
140	PL2303_PIPE_CLOSED,			/* pipe is closed */
141	PL2303_PIPE_IDLE,			/* open but no requests */
142	PL2303_PIPE_BUSY			/* servicing request */
143};
144
145/* various tunables */
146enum {
147	PL2303_BULKOUT_TIMEOUT		= 15,	/* bulkout timeout */
148	PL2303_BULKIN_TIMEOUT		= 15,	/* bulkin timeout */
149	PL2303_XFER_SZ_MAX		= 64,	/* max xfer size */
150	PL2303_CLEANUP_LEVEL_MAX	= 5	/* cleanup level */
151};
152
153
154/*
155 * debug printing masks
156 */
157#define	DPRINT_ATTACH		0x00000001
158#define	DPRINT_OPEN		0x00000002
159#define	DPRINT_CLOSE		0x00000004
160#define	DPRINT_DEF_PIPE		0x00000010
161#define	DPRINT_IN_PIPE		0x00000020
162#define	DPRINT_OUT_PIPE		0x00000040
163#define	DPRINT_IN_DATA		0x00000400
164#define	DPRINT_OUT_DATA		0x00000800
165#define	DPRINT_CTLOP		0x00001000
166#define	DPRINT_HOTPLUG		0x00002000
167#define	DPRINT_PM		0x00004000
168#define	DPRINT_MASK_ALL		0xFFFFFFFF
169
170
171/*
172 * misc macros
173 */
174#define	NELEM(a)	(sizeof (a) / sizeof (*(a)))
175
176#ifdef	__cplusplus
177}
178#endif
179
180#endif	/* _SYS_USB_USBSER_PL2303_VAR_H */
181