acpi: Narrow workaround for broken interrupt settings
[dragonfly.git] / sys / bus / u4b / serial / usb_serial.h
blobf23ab3c9d13ea404b704291b03c62e2d5c7ed470
1 /* $NetBSD: ucomvar.h,v 1.9 2001/01/23 21:56:17 augustss Exp $ */
2 /* $FreeBSD$ */
4 /*-
5 * Copyright (c) 2001-2002, Shunsuke Akiyama <akiyama@jp.FreeBSD.org>.
6 * All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
30 /*-
31 * Copyright (c) 1999 The NetBSD Foundation, Inc.
32 * All rights reserved.
34 * This code is derived from software contributed to The NetBSD Foundation
35 * by Lennart Augustsson (lennart@augustsson.net) at
36 * Carlstedt Research & Technology.
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
40 * are met:
41 * 1. Redistributions of source code must retain the above copyright
42 * notice, this list of conditions and the following disclaimer.
43 * 2. Redistributions in binary form must reproduce the above copyright
44 * notice, this list of conditions and the following disclaimer in the
45 * documentation and/or other materials provided with the distribution.
47 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
48 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
49 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
50 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
51 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
52 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
53 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
54 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
55 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
56 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
57 * POSSIBILITY OF SUCH DAMAGE.
60 #ifndef _USB_SERIAL_H_
61 #define _USB_SERIAL_H_
63 #include <sys/tty.h>
64 #include <sys/ttydefaults.h> /* for TTYDEF_* */
65 #include <sys/fcntl.h>
66 #include <sys/sysctl.h>
67 #include <sys/timepps.h>
69 /* We should seriously clean this up! */
70 #define SET(t, f) (t) |= (f)
71 #define CLR(t, f) (t) &= ~((unsigned)(f))
72 #define ISSET(t, f) ((t) & (f))
74 /* Module interface related macros */
75 #define UCOM_MODVER 1
77 #define UCOM_MINVER 1
78 #define UCOM_PREFVER UCOM_MODVER
79 #define UCOM_MAXVER 1
80 #define UCOM_JITTERBUF_SIZE 128 /* bytes */
82 struct usb_device;
83 struct ucom_softc;
84 struct usb_device_request;
85 struct thread;
88 * NOTE: There is no guarantee that "ucom_cfg_close()" will
89 * be called after "ucom_cfg_open()" if the device is detached
90 * while it is open!
92 struct ucom_callback {
93 void (*ucom_cfg_get_status) (struct ucom_softc *, uint8_t *plsr, uint8_t *pmsr);
94 void (*ucom_cfg_set_dtr) (struct ucom_softc *, uint8_t);
95 void (*ucom_cfg_set_rts) (struct ucom_softc *, uint8_t);
96 void (*ucom_cfg_set_break) (struct ucom_softc *, uint8_t);
97 void (*ucom_cfg_set_ring) (struct ucom_softc *, uint8_t);
98 void (*ucom_cfg_param) (struct ucom_softc *, struct termios *);
99 void (*ucom_cfg_open) (struct ucom_softc *);
100 void (*ucom_cfg_close) (struct ucom_softc *);
101 int (*ucom_pre_open) (struct ucom_softc *);
102 int (*ucom_pre_param) (struct ucom_softc *, struct termios *);
103 int (*ucom_ioctl) (struct ucom_softc *, uint32_t, caddr_t, int, struct thread *);
104 void (*ucom_start_read) (struct ucom_softc *);
105 void (*ucom_stop_read) (struct ucom_softc *);
106 void (*ucom_start_write) (struct ucom_softc *);
107 void (*ucom_stop_write) (struct ucom_softc *);
108 void (*ucom_tty_name) (struct ucom_softc *, char *pbuf, uint16_t buflen, uint16_t unit, uint16_t subunit);
109 void (*ucom_poll) (struct ucom_softc *);
110 void (*ucom_free) (struct ucom_softc *);
113 /* Line status register */
114 #define ULSR_RCV_FIFO 0x80
115 #define ULSR_TSRE 0x40 /* Transmitter empty: byte sent */
116 #define ULSR_TXRDY 0x20 /* Transmitter buffer empty */
117 #define ULSR_BI 0x10 /* Break detected */
118 #define ULSR_FE 0x08 /* Framing error: bad stop bit */
119 #define ULSR_PE 0x04 /* Parity error */
120 #define ULSR_OE 0x02 /* Overrun, lost incoming byte */
121 #define ULSR_RXRDY 0x01 /* Byte ready in Receive Buffer */
122 #define ULSR_RCV_MASK 0x1f /* Mask for incoming data or error */
124 struct ucom_cfg_task {
125 struct usb_proc_msg hdr;
126 struct ucom_softc *sc;
129 struct ucom_param_task {
130 struct usb_proc_msg hdr;
131 struct ucom_softc *sc;
132 struct termios termios_copy;
135 struct ucom_super_softc {
136 struct usb_process sc_tq;
137 int sc_unit;
138 int sc_subunits;
139 int sc_refs;
140 int sc_flag; /* see UCOM_FLAG_XXX */
141 struct sysctl_oid *sc_sysctl_ttyname;
142 struct sysctl_oid *sc_sysctl_ttyports;
143 char sc_ttyname[16];
146 struct ucom_softc {
148 * NOTE: To avoid losing level change information we use two
149 * tasks instead of one for all commands.
151 * Level changes are transitions like:
153 * ON->OFF
154 * OFF->ON
155 * OPEN->CLOSE
156 * CLOSE->OPEN
158 struct ucom_cfg_task sc_start_task[2];
159 struct ucom_cfg_task sc_open_task[2];
160 struct ucom_cfg_task sc_close_task[2];
161 struct ucom_cfg_task sc_line_state_task[2];
162 struct ucom_cfg_task sc_status_task[2];
163 struct ucom_param_task sc_param_task[2];
164 /* pulse capturing support, PPS */
165 struct pps_state sc_pps;
166 /* Used to set "UCOM_FLAG_GP_DATA" flag: */
167 struct usb_proc_msg *sc_last_start_xfer;
168 const struct ucom_callback *sc_callback;
169 struct ucom_super_softc *sc_super;
170 struct tty *sc_tty;
171 struct dev *sc_dev;
172 cdev_t sc_cdev; /* this is the /dev/ttyUX */
173 cdev_t sc_cdev_init; /* /dev/ttyUX.init */
174 cdev_t sc_cdev_lock; /* /dev/ttyUX.lock */
175 cdev_t sc_cdev2; /* /dev/cuaUX */
176 cdev_t sc_cdev2_init; /* /dev/cuaUX.init */
177 cdev_t sc_cdev2_lock; /* /dev/cuaUX.lock */
178 struct termios sc_it_in; /* Initial state in */
179 struct termios sc_it_out; /* Initial state out */
180 struct termios sc_lt_in; /* Lockstate in */
181 struct termios sc_lt_out; /* Lockstate out */
182 struct lock *sc_lock;
183 void *sc_parent;
184 int sc_subunit;
185 uint16_t sc_jitterbuf_in;
186 uint16_t sc_jitterbuf_out;
187 uint16_t sc_portno;
188 uint16_t sc_flag;
189 #define UCOM_FLAG_RTS_IFLOW 0x01 /* use RTS input flow control */
190 #define UCOM_FLAG_GONE 0x02 /* the device is gone */
191 #define UCOM_FLAG_ATTACHED 0x04 /* set if attached */
192 #define UCOM_FLAG_GP_DATA 0x08 /* set if get and put data is possible */
193 #define UCOM_FLAG_LL_READY 0x20 /* set if low layer is ready */
194 #define UCOM_FLAG_HL_READY 0x40 /* set if high layer is ready */
195 #define UCOM_FLAG_CONSOLE 0x80 /* set if device is a console */
196 #define UCOM_FLAG_WAIT_REFS 0x0100 /* set if we must wait for refs */
197 #define UCOM_FLAG_FREE_UNIT 0x0200 /* set if we must free the unit */
198 #define UCOM_FLAG_INWAKEUP 0x0400 /* set if we are in the tsw_inwakeup callback */
199 uint8_t sc_lsr;
200 uint8_t sc_msr;
201 uint8_t sc_mcr;
202 /* programmed line state bits */
203 uint8_t sc_pls_set; /* set bits */
204 uint8_t sc_pls_clr; /* cleared bits */
205 uint8_t sc_pls_curr; /* last state */
206 #define UCOM_LS_DTR 0x01
207 #define UCOM_LS_RTS 0x02
208 #define UCOM_LS_BREAK 0x04
209 #define UCOM_LS_RING 0x08
210 u_char hotchar;
211 uint8_t sc_jitterbuf[UCOM_JITTERBUF_SIZE];
214 #define UCOM_MTX_ASSERT(sc, what) KKASSERT(lockowned((sc)->sc_lock))
215 #define UCOM_MTX_LOCK(sc) lockmgr((sc)->sc_lock, LK_EXCLUSIVE)
216 #define UCOM_MTX_UNLOCK(sc) lockmgr((sc)->sc_lock, LK_RELEASE)
217 #define UCOM_UNLOAD_DRAIN(x) \
218 SYSUNINIT(var, SI_SUB_KLD - 3, SI_ORDER_ANY, ucom_drain_all, 0)
220 #define ucom_cfg_do_request(udev,com,req,ptr,flags,timo) \
221 usbd_do_request_proc(udev,&(com)->sc_super->sc_tq,req,ptr,flags,NULL,timo)
223 int ucom_attach(struct ucom_super_softc *,
224 struct ucom_softc *, int, void *,
225 const struct ucom_callback *callback, struct lock *);
226 void ucom_detach(struct ucom_super_softc *, struct ucom_softc *);
227 void ucom_set_pnpinfo_usb(struct ucom_super_softc *, device_t);
228 void ucom_status_change(struct ucom_softc *);
229 uint8_t ucom_get_data(struct ucom_softc *, struct usb_page_cache *,
230 uint32_t, uint32_t, uint32_t *);
231 void ucom_put_data(struct ucom_softc *, struct usb_page_cache *,
232 uint32_t, uint32_t);
233 uint8_t ucom_cfg_is_gone(struct ucom_softc *);
234 void ucom_drain(struct ucom_super_softc *);
235 void ucom_drain_all(void *);
236 void ucom_ref(struct ucom_super_softc *);
237 int ucom_unref(struct ucom_super_softc *);
238 #endif /* _USB_SERIAL_H_ */