uirdavar.h revision 1.2 1 /* $NetBSD: uirdavar.h,v 1.2 2007/12/05 07:15:54 ad Exp $ */
2
3 /*
4 * Copyright (c) 2001,2007 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Lennart Augustsson (lennart (at) augustsson.net).
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38 /*
39 * Protocol related definitions
40 */
41
42 #define UIRDA_INPUT_HEADER_SIZE 1
43 /* Inbound header byte */
44 #define UIRDA_MEDIA_BUSY 0x80
45 #define UIRDA_SPEED_MASK 0x0f
46 #define UIRDA_NO_SPEED 0x00
47 #define UIRDA_2400 0x01
48 #define UIRDA_9600 0x02
49 #define UIRDA_19200 0x03
50 #define UIRDA_38400 0x04
51 #define UIRDA_57600 0x05
52 #define UIRDA_115200 0x06
53 #define UIRDA_576000 0x07
54 #define UIRDA_1152000 0x08
55 #define UIRDA_4000000 0x09
56
57 #define UIRDA_OUTPUT_HEADER_SIZE 1
58 /* Outbound header byte */
59 #define UIRDA_EB_NO_CHANGE 0x00
60 #define UIRDA_EB_48 0x10
61 #define UIRDA_EB_24 0x20
62 #define UIRDA_EB_12 0x30
63 #define UIRDA_EB_6 0x40
64 #define UIRDA_EB_3 0x50
65 #define UIRDA_EB_2 0x60
66 #define UIRDA_EB_1 0x70
67 #define UIRDA_EB_0 0x80
68 /* Speeds as above */
69
70 #define UIRDA_WR_TIMEOUT 200
71
72 typedef struct {
73 uByte bLength;
74 uByte bDescriptorType;
75 #define UDESC_IRDA 0x21
76 uWord bcdSpecRevision;
77 uByte bmDataSize;
78 #define UI_DS_2048 0x20
79 #define UI_DS_1024 0x10
80 #define UI_DS_512 0x08
81 #define UI_DS_256 0x04
82 #define UI_DS_128 0x02
83 #define UI_DS_64 0x01
84 uByte bmWindowSize;
85 #define UI_WS_7 0x40
86 #define UI_WS_6 0x20
87 #define UI_WS_5 0x10
88 #define UI_WS_4 0x08
89 #define UI_WS_3 0x04
90 #define UI_WS_2 0x02
91 #define UI_WS_1 0x01
92 uByte bmMinTurnaroundTime;
93 #define UI_TA_0 0x80
94 #define UI_TA_10 0x40
95 #define UI_TA_50 0x20
96 #define UI_TA_100 0x10
97 #define UI_TA_500 0x08
98 #define UI_TA_1000 0x04
99 #define UI_TA_5000 0x02
100 #define UI_TA_10000 0x01
101 uWord wBaudRate;
102 #define UI_BR_4000000 0x0100
103 #define UI_BR_1152000 0x0080
104 #define UI_BR_576000 0x0040
105 #define UI_BR_115200 0x0020
106 #define UI_BR_57600 0x0010
107 #define UI_BR_38400 0x0008
108 #define UI_BR_19200 0x0004
109 #define UI_BR_9600 0x0002
110 #define UI_BR_2400 0x0001
111 uByte bmAdditionalBOFs;
112 #define UI_EB_0 0x80
113 #define UI_EB_1 0x40
114 #define UI_EB_2 0x20
115 #define UI_EB_3 0x10
116 #define UI_EB_6 0x08
117 #define UI_EB_12 0x04
118 #define UI_EB_24 0x02
119 #define UI_EB_48 0x01
120 uByte bIrdaSniff;
121 uByte bMaxUnicastList;
122 } UPACKED usb_irda_descriptor_t;
123 #define USB_IRDA_DESCRIPTOR_SIZE 12
124
125
126 struct uirda_softc {
127 USBBASEDEVICE sc_dev;
128 usbd_device_handle sc_udev;
129 usbd_interface_handle sc_iface;
130
131 kmutex_t sc_rd_buf_lk;
132 u_int8_t *sc_rd_buf;
133 int sc_rd_addr;
134 usbd_pipe_handle sc_rd_pipe;
135 usbd_xfer_handle sc_rd_xfer;
136 struct selinfo sc_rd_sel;
137 u_int sc_rd_count;
138 u_char sc_rd_err;
139
140 kmutex_t sc_wr_buf_lk;
141 u_int8_t *sc_wr_buf;
142 int sc_wr_addr;
143 usbd_xfer_handle sc_wr_xfer;
144 usbd_pipe_handle sc_wr_pipe;
145 int sc_wr_hdr;
146 struct selinfo sc_wr_sel;
147
148 struct device *sc_child;
149 struct irda_params sc_params;
150 usb_irda_descriptor_t sc_irdadesc;
151
152 int sc_refcnt;
153 char sc_dying;
154 u_int8_t sc_hdszi; /* set to value if != 1 needed */
155
156 int (*sc_loadfw)(struct uirda_softc *);
157 struct irframe_methods *sc_irm;
158 };
159
160 usbd_status usbd_get_class_desc(usbd_device_handle, int type, int index,
161 int len, void *desc);
162
163 int uirda_open(void *h, int flag, int mode, struct lwp *l);
164 int uirda_close(void *h, int flag, int mode, struct lwp *l);
165 int uirda_read(void *h, struct uio *uio, int flag);
166 int uirda_write(void *h, struct uio *uio, int flag);
167 int uirda_set_params(void *h, struct irda_params *params);
168 int uirda_get_speeds(void *h, int *speeds);
169 int uirda_get_turnarounds(void *h, int *times);
170 int uirda_poll(void *h, int events, struct lwp *l);
171 int uirda_kqfilter(void *h, struct knote *kn);
172