pseye.c revision 1.7.2.2 1 1.7.2.2 wrstuden /* $NetBSD: pseye.c,v 1.7.2.2 2008/09/18 04:35:11 wrstuden Exp $ */
2 1.7.2.2 wrstuden
3 1.7.2.2 wrstuden /*-
4 1.7.2.2 wrstuden * Copyright (c) 2008 Jared D. McNeill <jmcneill (at) invisible.ca>
5 1.7.2.2 wrstuden * All rights reserved.
6 1.7.2.2 wrstuden *
7 1.7.2.2 wrstuden * Redistribution and use in source and binary forms, with or without
8 1.7.2.2 wrstuden * modification, are permitted provided that the following conditions
9 1.7.2.2 wrstuden * are met:
10 1.7.2.2 wrstuden * 1. Redistributions of source code must retain the above copyright
11 1.7.2.2 wrstuden * notice, this list of conditions and the following disclaimer.
12 1.7.2.2 wrstuden * 2. Redistributions in binary form must reproduce the above copyright
13 1.7.2.2 wrstuden * notice, this list of conditions and the following disclaimer in the
14 1.7.2.2 wrstuden * documentation and/or other materials provided with the distribution.
15 1.7.2.2 wrstuden *
16 1.7.2.2 wrstuden * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 1.7.2.2 wrstuden * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 1.7.2.2 wrstuden * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 1.7.2.2 wrstuden * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 1.7.2.2 wrstuden * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 1.7.2.2 wrstuden * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 1.7.2.2 wrstuden * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 1.7.2.2 wrstuden * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 1.7.2.2 wrstuden * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 1.7.2.2 wrstuden * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 1.7.2.2 wrstuden * POSSIBILITY OF SUCH DAMAGE.
27 1.7.2.2 wrstuden */
28 1.7.2.2 wrstuden
29 1.7.2.2 wrstuden /*
30 1.7.2.2 wrstuden * Sony PLAYSTATION(R) Eye Driver
31 1.7.2.2 wrstuden *
32 1.7.2.2 wrstuden * The only documentation we have for this part is based on a series
33 1.7.2.2 wrstuden * of forum postings by Jim Paris on ps2dev.org. Many thanks for
34 1.7.2.2 wrstuden * figuring this one out.
35 1.7.2.2 wrstuden *
36 1.7.2.2 wrstuden * URL: http://forums.ps2dev.org/viewtopic.php?t=9238
37 1.7.2.2 wrstuden */
38 1.7.2.2 wrstuden
39 1.7.2.2 wrstuden #include <sys/cdefs.h>
40 1.7.2.2 wrstuden __KERNEL_RCSID(0, "$NetBSD: pseye.c,v 1.7.2.2 2008/09/18 04:35:11 wrstuden Exp $");
41 1.7.2.2 wrstuden
42 1.7.2.2 wrstuden #include <sys/param.h>
43 1.7.2.2 wrstuden #include <sys/systm.h>
44 1.7.2.2 wrstuden #include <sys/device.h>
45 1.7.2.2 wrstuden #include <sys/malloc.h>
46 1.7.2.2 wrstuden #include <sys/fcntl.h>
47 1.7.2.2 wrstuden #include <sys/conf.h>
48 1.7.2.2 wrstuden #include <sys/poll.h>
49 1.7.2.2 wrstuden #include <sys/bus.h>
50 1.7.2.2 wrstuden #include <sys/mutex.h>
51 1.7.2.2 wrstuden #include <sys/kthread.h>
52 1.7.2.2 wrstuden #include <sys/condvar.h>
53 1.7.2.2 wrstuden
54 1.7.2.2 wrstuden #include <uvm/uvm_extern.h>
55 1.7.2.2 wrstuden
56 1.7.2.2 wrstuden #include <dev/usb/usb.h>
57 1.7.2.2 wrstuden #include <dev/usb/usbdi.h>
58 1.7.2.2 wrstuden #include <dev/usb/usbdi_util.h>
59 1.7.2.2 wrstuden #include <dev/usb/usbdevs.h>
60 1.7.2.2 wrstuden
61 1.7.2.2 wrstuden #include <dev/video_if.h>
62 1.7.2.2 wrstuden
63 1.7.2.2 wrstuden #define PRI_PSEYE PRI_BIO
64 1.7.2.2 wrstuden
65 1.7.2.2 wrstuden /* Bulk-in buffer length */
66 1.7.2.2 wrstuden #define PSEYE_BULKIN_BUFLEN (640 * 480 * 2)
67 1.7.2.2 wrstuden
68 1.7.2.2 wrstuden /* SCCB/sensor interface */
69 1.7.2.2 wrstuden #define PSEYE_SCCB_ADDRESS 0xf1
70 1.7.2.2 wrstuden #define PSEYE_SCCB_SUBADDR 0xf2
71 1.7.2.2 wrstuden #define PSEYE_SCCB_WRITE 0xf3
72 1.7.2.2 wrstuden #define PSEYE_SCCB_READ 0xf4
73 1.7.2.2 wrstuden #define PSEYE_SCCB_OPERATION 0xf5
74 1.7.2.2 wrstuden #define PSEYE_SCCB_STATUS 0xf6
75 1.7.2.2 wrstuden
76 1.7.2.2 wrstuden #define PSEYE_SCCB_OP_WRITE_3 0x37
77 1.7.2.2 wrstuden #define PSEYE_SCCB_OP_WRITE_2 0x33
78 1.7.2.2 wrstuden #define PSEYE_SCCB_OP_READ_2 0xf9
79 1.7.2.2 wrstuden
80 1.7.2.2 wrstuden struct pseye_softc {
81 1.7.2.2 wrstuden USBBASEDEVICE sc_dev;
82 1.7.2.2 wrstuden
83 1.7.2.2 wrstuden usbd_device_handle sc_udev;
84 1.7.2.2 wrstuden usbd_interface_handle sc_iface;
85 1.7.2.2 wrstuden
86 1.7.2.2 wrstuden device_t sc_videodev;
87 1.7.2.2 wrstuden char sc_running;
88 1.7.2.2 wrstuden
89 1.7.2.2 wrstuden kcondvar_t sc_cv;
90 1.7.2.2 wrstuden kmutex_t sc_mtx;
91 1.7.2.2 wrstuden
92 1.7.2.2 wrstuden usbd_pipe_handle sc_bulkin_pipe;
93 1.7.2.2 wrstuden usbd_xfer_handle sc_bulkin_xfer;
94 1.7.2.2 wrstuden int sc_bulkin;
95 1.7.2.2 wrstuden uint8_t *sc_bulkin_buffer;
96 1.7.2.2 wrstuden int sc_bulkin_bufferlen;
97 1.7.2.2 wrstuden
98 1.7.2.2 wrstuden char sc_dying;
99 1.7.2.2 wrstuden };
100 1.7.2.2 wrstuden
101 1.7.2.2 wrstuden static int pseye_match(device_t, cfdata_t, void *);
102 1.7.2.2 wrstuden static void pseye_attach(device_t, device_t, void *);
103 1.7.2.2 wrstuden static int pseye_detach(device_t, int);
104 1.7.2.2 wrstuden static void pseye_childdet(device_t, device_t);
105 1.7.2.2 wrstuden static int pseye_activate(device_t, enum devact);
106 1.7.2.2 wrstuden
107 1.7.2.2 wrstuden static void pseye_init(struct pseye_softc *);
108 1.7.2.2 wrstuden static void pseye_sccb_init(struct pseye_softc *);
109 1.7.2.2 wrstuden static void pseye_stop(struct pseye_softc *);
110 1.7.2.2 wrstuden static void pseye_start(struct pseye_softc *);
111 1.7.2.2 wrstuden static void pseye_led(struct pseye_softc *, bool);
112 1.7.2.2 wrstuden static uint8_t pseye_getreg(struct pseye_softc *, uint16_t);
113 1.7.2.2 wrstuden static void pseye_setreg(struct pseye_softc *, uint16_t, uint8_t);
114 1.7.2.2 wrstuden static void pseye_setregv(struct pseye_softc *, uint16_t, uint8_t);
115 1.7.2.2 wrstuden static void pseye_sccb_setreg(struct pseye_softc *, uint8_t, uint8_t);
116 1.7.2.2 wrstuden static bool pseye_sccb_status(struct pseye_softc *);
117 1.7.2.2 wrstuden
118 1.7.2.2 wrstuden static int pseye_init_pipes(struct pseye_softc *);
119 1.7.2.2 wrstuden static int pseye_close_pipes(struct pseye_softc *);
120 1.7.2.2 wrstuden
121 1.7.2.2 wrstuden static usbd_status pseye_get_frame(struct pseye_softc *);
122 1.7.2.2 wrstuden
123 1.7.2.2 wrstuden /* video(9) API */
124 1.7.2.2 wrstuden static int pseye_open(void *, int);
125 1.7.2.2 wrstuden static void pseye_close(void *);
126 1.7.2.2 wrstuden static const char * pseye_get_devname(void *);
127 1.7.2.2 wrstuden static int pseye_enum_format(void *, uint32_t,
128 1.7.2.2 wrstuden struct video_format *);
129 1.7.2.2 wrstuden static int pseye_get_format(void *, struct video_format *);
130 1.7.2.2 wrstuden static int pseye_set_format(void *, struct video_format *);
131 1.7.2.2 wrstuden static int pseye_try_format(void *, struct video_format *);
132 1.7.2.2 wrstuden static int pseye_start_transfer(void *);
133 1.7.2.2 wrstuden static int pseye_stop_transfer(void *);
134 1.7.2.2 wrstuden
135 1.7.2.2 wrstuden CFATTACH_DECL2_NEW(pseye, sizeof(struct pseye_softc),
136 1.7.2.2 wrstuden pseye_match, pseye_attach, pseye_detach, pseye_activate,
137 1.7.2.2 wrstuden NULL, pseye_childdet);
138 1.7.2.2 wrstuden
139 1.7.2.2 wrstuden static const struct video_hw_if pseye_hw_if = {
140 1.7.2.2 wrstuden .open = pseye_open,
141 1.7.2.2 wrstuden .close = pseye_close,
142 1.7.2.2 wrstuden .get_devname = pseye_get_devname,
143 1.7.2.2 wrstuden .enum_format = pseye_enum_format,
144 1.7.2.2 wrstuden .get_format = pseye_get_format,
145 1.7.2.2 wrstuden .set_format = pseye_set_format,
146 1.7.2.2 wrstuden .try_format = pseye_try_format,
147 1.7.2.2 wrstuden .start_transfer = pseye_start_transfer,
148 1.7.2.2 wrstuden .stop_transfer = pseye_stop_transfer,
149 1.7.2.2 wrstuden .control_iter_init = NULL,
150 1.7.2.2 wrstuden .control_iter_next = NULL,
151 1.7.2.2 wrstuden .get_control_desc_group = NULL,
152 1.7.2.2 wrstuden .get_control_group = NULL,
153 1.7.2.2 wrstuden .set_control_group = NULL,
154 1.7.2.2 wrstuden };
155 1.7.2.2 wrstuden
156 1.7.2.2 wrstuden USB_MATCH(pseye)
157 1.7.2.2 wrstuden {
158 1.7.2.2 wrstuden USB_IFMATCH_START(pseye, uaa);
159 1.7.2.2 wrstuden
160 1.7.2.2 wrstuden if (uaa->class != UICLASS_VENDOR)
161 1.7.2.2 wrstuden return UMATCH_NONE;
162 1.7.2.2 wrstuden
163 1.7.2.2 wrstuden if (uaa->vendor == USB_VENDOR_OMNIVISION2) {
164 1.7.2.2 wrstuden switch (uaa->product) {
165 1.7.2.2 wrstuden case USB_PRODUCT_OMNIVISION2_PSEYE:
166 1.7.2.2 wrstuden if (uaa->ifaceno != 0)
167 1.7.2.2 wrstuden return UMATCH_NONE;
168 1.7.2.2 wrstuden return UMATCH_VENDOR_PRODUCT;
169 1.7.2.2 wrstuden }
170 1.7.2.2 wrstuden }
171 1.7.2.2 wrstuden
172 1.7.2.2 wrstuden return UMATCH_NONE;
173 1.7.2.2 wrstuden }
174 1.7.2.2 wrstuden
175 1.7.2.2 wrstuden USB_ATTACH(pseye)
176 1.7.2.2 wrstuden {
177 1.7.2.2 wrstuden USB_IFATTACH_START(pseye, sc, uaa);
178 1.7.2.2 wrstuden usbd_device_handle dev = uaa->device;
179 1.7.2.2 wrstuden usb_interface_descriptor_t *id = NULL;
180 1.7.2.2 wrstuden usb_endpoint_descriptor_t *ed = NULL, *ed_bulkin = NULL;
181 1.7.2.2 wrstuden char *devinfo;
182 1.7.2.2 wrstuden int i;
183 1.7.2.2 wrstuden
184 1.7.2.2 wrstuden USB_ATTACH_SETUP;
185 1.7.2.2 wrstuden devinfo = usbd_devinfo_alloc(dev, 0);
186 1.7.2.2 wrstuden aprint_normal_dev(self, "%s\n", devinfo);
187 1.7.2.2 wrstuden usbd_devinfo_free(devinfo);
188 1.7.2.2 wrstuden
189 1.7.2.2 wrstuden sc->sc_dev = self;
190 1.7.2.2 wrstuden sc->sc_udev = dev;
191 1.7.2.2 wrstuden sc->sc_iface = uaa->iface;
192 1.7.2.2 wrstuden sc->sc_bulkin_bufferlen = PSEYE_BULKIN_BUFLEN;
193 1.7.2.2 wrstuden
194 1.7.2.2 wrstuden sc->sc_dying = sc->sc_running = 0;
195 1.7.2.2 wrstuden cv_init(&sc->sc_cv, device_xname(sc->sc_dev));
196 1.7.2.2 wrstuden mutex_init(&sc->sc_mtx, MUTEX_DEFAULT, IPL_NONE);
197 1.7.2.2 wrstuden
198 1.7.2.2 wrstuden id = usbd_get_interface_descriptor(sc->sc_iface);
199 1.7.2.2 wrstuden if (id == NULL) {
200 1.7.2.2 wrstuden aprint_error_dev(self, "failed to get interface descriptor\n");
201 1.7.2.2 wrstuden sc->sc_dying = 1;
202 1.7.2.2 wrstuden USB_ATTACH_ERROR_RETURN;
203 1.7.2.2 wrstuden }
204 1.7.2.2 wrstuden
205 1.7.2.2 wrstuden for (i = 0; i < id->bNumEndpoints; i++) {
206 1.7.2.2 wrstuden ed = usbd_interface2endpoint_descriptor(sc->sc_iface, i);
207 1.7.2.2 wrstuden if (ed == NULL) {
208 1.7.2.2 wrstuden aprint_error_dev(sc->sc_dev, "couldn't get ep %d\n", i);
209 1.7.2.2 wrstuden sc->sc_dying = 1;
210 1.7.2.2 wrstuden USB_ATTACH_ERROR_RETURN;
211 1.7.2.2 wrstuden }
212 1.7.2.2 wrstuden
213 1.7.2.2 wrstuden if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
214 1.7.2.2 wrstuden UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
215 1.7.2.2 wrstuden ed_bulkin = ed;
216 1.7.2.2 wrstuden break;
217 1.7.2.2 wrstuden }
218 1.7.2.2 wrstuden }
219 1.7.2.2 wrstuden
220 1.7.2.2 wrstuden if (ed_bulkin == NULL) {
221 1.7.2.2 wrstuden aprint_error_dev(sc->sc_dev, "no bulk-in endpoint found\n");
222 1.7.2.2 wrstuden sc->sc_dying = 1;
223 1.7.2.2 wrstuden USB_ATTACH_ERROR_RETURN;
224 1.7.2.2 wrstuden }
225 1.7.2.2 wrstuden
226 1.7.2.2 wrstuden sc->sc_bulkin = ed_bulkin->bEndpointAddress;
227 1.7.2.2 wrstuden
228 1.7.2.2 wrstuden sc->sc_bulkin_xfer = usbd_alloc_xfer(sc->sc_udev);
229 1.7.2.2 wrstuden if (sc->sc_bulkin_xfer == NULL) {
230 1.7.2.2 wrstuden sc->sc_dying = 1;
231 1.7.2.2 wrstuden USB_ATTACH_ERROR_RETURN;
232 1.7.2.2 wrstuden }
233 1.7.2.2 wrstuden sc->sc_bulkin_buffer = usbd_alloc_buffer(sc->sc_bulkin_xfer,
234 1.7.2.2 wrstuden sc->sc_bulkin_bufferlen);
235 1.7.2.2 wrstuden if (sc->sc_bulkin_buffer == NULL) {
236 1.7.2.2 wrstuden usbd_free_xfer(sc->sc_bulkin_xfer);
237 1.7.2.2 wrstuden sc->sc_bulkin_xfer = NULL;
238 1.7.2.2 wrstuden sc->sc_dying = 1;
239 1.7.2.2 wrstuden USB_ATTACH_ERROR_RETURN;
240 1.7.2.2 wrstuden }
241 1.7.2.2 wrstuden
242 1.7.2.2 wrstuden pseye_init(sc);
243 1.7.2.2 wrstuden
244 1.7.2.2 wrstuden sc->sc_videodev = video_attach_mi(&pseye_hw_if, sc->sc_dev);
245 1.7.2.2 wrstuden if (sc->sc_videodev == NULL) {
246 1.7.2.2 wrstuden aprint_error_dev(sc->sc_dev, "couldn't attach video layer\n");
247 1.7.2.2 wrstuden sc->sc_dying = 1;
248 1.7.2.2 wrstuden USB_ATTACH_ERROR_RETURN;
249 1.7.2.2 wrstuden }
250 1.7.2.2 wrstuden
251 1.7.2.2 wrstuden usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, sc->sc_udev,
252 1.7.2.2 wrstuden USBDEV(sc->sc_dev));
253 1.7.2.2 wrstuden
254 1.7.2.2 wrstuden USB_ATTACH_SUCCESS_RETURN;
255 1.7.2.2 wrstuden }
256 1.7.2.2 wrstuden
257 1.7.2.2 wrstuden USB_DETACH(pseye)
258 1.7.2.2 wrstuden {
259 1.7.2.2 wrstuden USB_DETACH_START(pseye, sc);
260 1.7.2.2 wrstuden
261 1.7.2.2 wrstuden sc->sc_dying = 1;
262 1.7.2.2 wrstuden
263 1.7.2.2 wrstuden if (sc->sc_videodev != NULL) {
264 1.7.2.2 wrstuden config_detach(sc->sc_videodev, flags);
265 1.7.2.2 wrstuden sc->sc_videodev = NULL;
266 1.7.2.2 wrstuden }
267 1.7.2.2 wrstuden
268 1.7.2.2 wrstuden if (sc->sc_bulkin_xfer != NULL) {
269 1.7.2.2 wrstuden usbd_free_xfer(sc->sc_bulkin_xfer);
270 1.7.2.2 wrstuden sc->sc_bulkin_xfer = NULL;
271 1.7.2.2 wrstuden }
272 1.7.2.2 wrstuden
273 1.7.2.2 wrstuden if (sc->sc_bulkin_pipe != NULL) {
274 1.7.2.2 wrstuden usbd_abort_pipe(sc->sc_bulkin_pipe);
275 1.7.2.2 wrstuden sc->sc_bulkin_pipe = NULL;
276 1.7.2.2 wrstuden }
277 1.7.2.2 wrstuden
278 1.7.2.2 wrstuden mutex_enter(&sc->sc_mtx);
279 1.7.2.2 wrstuden if (sc->sc_running) {
280 1.7.2.2 wrstuden sc->sc_running = 0;
281 1.7.2.2 wrstuden cv_wait_sig(&sc->sc_cv, &sc->sc_mtx);
282 1.7.2.2 wrstuden }
283 1.7.2.2 wrstuden mutex_exit(&sc->sc_mtx);
284 1.7.2.2 wrstuden
285 1.7.2.2 wrstuden cv_destroy(&sc->sc_cv);
286 1.7.2.2 wrstuden mutex_destroy(&sc->sc_mtx);
287 1.7.2.2 wrstuden
288 1.7.2.2 wrstuden usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_udev,
289 1.7.2.2 wrstuden USBDEV(sc->sc_dev));
290 1.7.2.2 wrstuden
291 1.7.2.2 wrstuden return 0;
292 1.7.2.2 wrstuden }
293 1.7.2.2 wrstuden
294 1.7.2.2 wrstuden int
295 1.7.2.2 wrstuden pseye_activate(device_ptr_t self, enum devact act)
296 1.7.2.2 wrstuden {
297 1.7.2.2 wrstuden struct pseye_softc *sc = device_private(self);
298 1.7.2.2 wrstuden int rv;
299 1.7.2.2 wrstuden
300 1.7.2.2 wrstuden rv = 0;
301 1.7.2.2 wrstuden
302 1.7.2.2 wrstuden switch (act) {
303 1.7.2.2 wrstuden case DVACT_ACTIVATE:
304 1.7.2.2 wrstuden break;
305 1.7.2.2 wrstuden case DVACT_DEACTIVATE:
306 1.7.2.2 wrstuden sc->sc_dying = 1;
307 1.7.2.2 wrstuden break;
308 1.7.2.2 wrstuden }
309 1.7.2.2 wrstuden
310 1.7.2.2 wrstuden return rv;
311 1.7.2.2 wrstuden }
312 1.7.2.2 wrstuden
313 1.7.2.2 wrstuden static void
314 1.7.2.2 wrstuden pseye_childdet(device_t self, device_t child)
315 1.7.2.2 wrstuden {
316 1.7.2.2 wrstuden struct pseye_softc *sc = device_private(self);
317 1.7.2.2 wrstuden
318 1.7.2.2 wrstuden if (sc->sc_videodev) {
319 1.7.2.2 wrstuden KASSERT(sc->sc_videodev == child);
320 1.7.2.2 wrstuden sc->sc_videodev = NULL;
321 1.7.2.2 wrstuden }
322 1.7.2.2 wrstuden }
323 1.7.2.2 wrstuden
324 1.7.2.2 wrstuden /*
325 1.7.2.2 wrstuden * Device access
326 1.7.2.2 wrstuden */
327 1.7.2.2 wrstuden
328 1.7.2.2 wrstuden static void
329 1.7.2.2 wrstuden pseye_init(struct pseye_softc *sc)
330 1.7.2.2 wrstuden {
331 1.7.2.2 wrstuden pseye_sccb_init(sc);
332 1.7.2.2 wrstuden
333 1.7.2.2 wrstuden pseye_setregv(sc, 0xc2, 0x0c);
334 1.7.2.2 wrstuden pseye_setregv(sc, 0x88, 0xf8);
335 1.7.2.2 wrstuden pseye_setregv(sc, 0xc3, 0x69);
336 1.7.2.2 wrstuden pseye_setregv(sc, 0x89, 0xff);
337 1.7.2.2 wrstuden pseye_setregv(sc, 0x76, 0x03);
338 1.7.2.2 wrstuden pseye_setregv(sc, 0x92, 0x01);
339 1.7.2.2 wrstuden pseye_setregv(sc, 0x93, 0x18);
340 1.7.2.2 wrstuden pseye_setregv(sc, 0x94, 0x10);
341 1.7.2.2 wrstuden pseye_setregv(sc, 0x95, 0x10);
342 1.7.2.2 wrstuden pseye_setregv(sc, 0xe2, 0x00);
343 1.7.2.2 wrstuden pseye_setregv(sc, 0xe7, 0x3e);
344 1.7.2.2 wrstuden
345 1.7.2.2 wrstuden pseye_setreg(sc, 0x1c, 0x0a);
346 1.7.2.2 wrstuden pseye_setreg(sc, 0x1d, 0x22);
347 1.7.2.2 wrstuden pseye_setreg(sc, 0x1d, 0x06);
348 1.7.2.2 wrstuden pseye_setregv(sc, 0x96, 0x00);
349 1.7.2.2 wrstuden
350 1.7.2.2 wrstuden pseye_setreg(sc, 0x97, 0x20);
351 1.7.2.2 wrstuden pseye_setreg(sc, 0x97, 0x20);
352 1.7.2.2 wrstuden pseye_setreg(sc, 0x97, 0x20);
353 1.7.2.2 wrstuden pseye_setreg(sc, 0x97, 0x0a);
354 1.7.2.2 wrstuden pseye_setreg(sc, 0x97, 0x3f);
355 1.7.2.2 wrstuden pseye_setreg(sc, 0x97, 0x4a);
356 1.7.2.2 wrstuden pseye_setreg(sc, 0x97, 0x20);
357 1.7.2.2 wrstuden pseye_setreg(sc, 0x97, 0x15);
358 1.7.2.2 wrstuden pseye_setreg(sc, 0x97, 0x0b);
359 1.7.2.2 wrstuden
360 1.7.2.2 wrstuden pseye_setregv(sc, 0x8e, 0x40);
361 1.7.2.2 wrstuden pseye_setregv(sc, 0x1f, 0x81);
362 1.7.2.2 wrstuden pseye_setregv(sc, 0x34, 0x05);
363 1.7.2.2 wrstuden pseye_setregv(sc, 0xe3, 0x04);
364 1.7.2.2 wrstuden pseye_setregv(sc, 0x88, 0x00);
365 1.7.2.2 wrstuden pseye_setregv(sc, 0x89, 0x00);
366 1.7.2.2 wrstuden pseye_setregv(sc, 0x76, 0x00);
367 1.7.2.2 wrstuden pseye_setregv(sc, 0xe7, 0x2e);
368 1.7.2.2 wrstuden pseye_setregv(sc, 0x31, 0xf9);
369 1.7.2.2 wrstuden pseye_setregv(sc, 0x25, 0x42);
370 1.7.2.2 wrstuden pseye_setregv(sc, 0x21, 0xf0);
371 1.7.2.2 wrstuden
372 1.7.2.2 wrstuden pseye_setreg(sc, 0x1c, 0x00);
373 1.7.2.2 wrstuden pseye_setreg(sc, 0x1d, 0x40);
374 1.7.2.2 wrstuden pseye_setreg(sc, 0x1d, 0x02);
375 1.7.2.2 wrstuden pseye_setreg(sc, 0x1d, 0x00);
376 1.7.2.2 wrstuden pseye_setreg(sc, 0x1d, 0x02);
377 1.7.2.2 wrstuden pseye_setreg(sc, 0x1d, 0x57);
378 1.7.2.2 wrstuden pseye_setreg(sc, 0x1d, 0xff);
379 1.7.2.2 wrstuden
380 1.7.2.2 wrstuden pseye_setregv(sc, 0x8d, 0x1c);
381 1.7.2.2 wrstuden pseye_setregv(sc, 0x8e, 0x80);
382 1.7.2.2 wrstuden pseye_setregv(sc, 0xe5, 0x04);
383 1.7.2.2 wrstuden
384 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x12, 0x80);
385 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x11, 0x01);
386 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x11, 0x01);
387 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x11, 0x01);
388 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x11, 0x01);
389 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x11, 0x01);
390 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x11, 0x01);
391 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x11, 0x01);
392 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x11, 0x01);
393 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x11, 0x01);
394 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x11, 0x01);
395 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x11, 0x01);
396 1.7.2.2 wrstuden
397 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x3d, 0x03);
398 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x17, 0x26);
399 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x18, 0xa0);
400 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x19, 0x07);
401 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x1a, 0xf0);
402 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x32, 0x00);
403 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x29, 0xa0);
404 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x2c, 0xf0);
405 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x65, 0x20);
406 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x11, 0x01);
407 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x42, 0x7f);
408 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x63, 0xe0);
409 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x64, 0xff);
410 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x66, 0x00);
411 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x13, 0xf0);
412 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x0d, 0x41);
413 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x0f, 0xc5);
414 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x14, 0x11);
415 1.7.2.2 wrstuden
416 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x22, 0x7f);
417 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x23, 0x03);
418 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x24, 0x40);
419 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x25, 0x30);
420 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x26, 0xa1);
421 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x2a, 0x00);
422 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x2b, 0x00);
423 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x6b, 0xaa);
424 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x13, 0xff);
425 1.7.2.2 wrstuden
426 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x90, 0x05);
427 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x91, 0x01);
428 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x92, 0x03);
429 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x93, 0x00);
430 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x94, 0x60);
431 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x95, 0x3c);
432 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x96, 0x24);
433 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x97, 0x1e);
434 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x98, 0x62);
435 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x99, 0x80);
436 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x9a, 0x1e);
437 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x9b, 0x08);
438 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x9c, 0x20);
439 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x9e, 0x81);
440 1.7.2.2 wrstuden
441 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0xa6, 0x04);
442 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x7e, 0x0c);
443 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x7f, 0x16);
444 1.7.2.2 wrstuden
445 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x80, 0x2a);
446 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x81, 0x4e);
447 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x82, 0x61);
448 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x83, 0x6f);
449 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x84, 0x7b);
450 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x85, 0x86);
451 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x86, 0x8e);
452 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x87, 0x97);
453 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x88, 0xa4);
454 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x89, 0xaf);
455 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x8a, 0xc5);
456 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x8b, 0xd7);
457 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x8c, 0xe8);
458 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x8d, 0x20);
459 1.7.2.2 wrstuden
460 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x0c, 0x90);
461 1.7.2.2 wrstuden
462 1.7.2.2 wrstuden pseye_setregv(sc, 0xc0, 0x50);
463 1.7.2.2 wrstuden pseye_setregv(sc, 0xc1, 0x3c);
464 1.7.2.2 wrstuden pseye_setregv(sc, 0xc2, 0x0c);
465 1.7.2.2 wrstuden
466 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x2b, 0x00);
467 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x22, 0x7f);
468 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x23, 0x03);
469 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x11, 0x01);
470 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x0c, 0xd0);
471 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x64, 0xff);
472 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x0d, 0x41);
473 1.7.2.2 wrstuden
474 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x14, 0x41);
475 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x0e, 0xcd);
476 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0xac, 0xbf);
477 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x8e, 0x00);
478 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x0c, 0xd0);
479 1.7.2.2 wrstuden
480 1.7.2.2 wrstuden pseye_stop(sc);
481 1.7.2.2 wrstuden }
482 1.7.2.2 wrstuden
483 1.7.2.2 wrstuden static void
484 1.7.2.2 wrstuden pseye_sccb_init(struct pseye_softc *sc)
485 1.7.2.2 wrstuden {
486 1.7.2.2 wrstuden pseye_setregv(sc, 0xe7, 0x3a);
487 1.7.2.2 wrstuden pseye_setreg(sc, PSEYE_SCCB_ADDRESS, 0x60);
488 1.7.2.2 wrstuden pseye_setreg(sc, PSEYE_SCCB_ADDRESS, 0x60);
489 1.7.2.2 wrstuden pseye_setreg(sc, PSEYE_SCCB_ADDRESS, 0x60);
490 1.7.2.2 wrstuden pseye_setreg(sc, PSEYE_SCCB_ADDRESS, 0x42);
491 1.7.2.2 wrstuden }
492 1.7.2.2 wrstuden
493 1.7.2.2 wrstuden static void
494 1.7.2.2 wrstuden pseye_stop(struct pseye_softc *sc)
495 1.7.2.2 wrstuden {
496 1.7.2.2 wrstuden pseye_led(sc, false);
497 1.7.2.2 wrstuden pseye_setreg(sc, 0xe0, 0x09);
498 1.7.2.2 wrstuden }
499 1.7.2.2 wrstuden
500 1.7.2.2 wrstuden static void
501 1.7.2.2 wrstuden pseye_start(struct pseye_softc *sc)
502 1.7.2.2 wrstuden {
503 1.7.2.2 wrstuden pseye_led(sc, true);
504 1.7.2.2 wrstuden pseye_setreg(sc, 0xe0, 0x00);
505 1.7.2.2 wrstuden }
506 1.7.2.2 wrstuden
507 1.7.2.2 wrstuden static void
508 1.7.2.2 wrstuden pseye_led(struct pseye_softc *sc, bool enabled)
509 1.7.2.2 wrstuden {
510 1.7.2.2 wrstuden uint8_t val;
511 1.7.2.2 wrstuden
512 1.7.2.2 wrstuden val = pseye_getreg(sc, 0x21);
513 1.7.2.2 wrstuden pseye_setreg(sc, 0x21, val | 0x80);
514 1.7.2.2 wrstuden
515 1.7.2.2 wrstuden val = pseye_getreg(sc, 0x23);
516 1.7.2.2 wrstuden if (enabled == true)
517 1.7.2.2 wrstuden val |= 0x80;
518 1.7.2.2 wrstuden else
519 1.7.2.2 wrstuden val &= ~0x80;
520 1.7.2.2 wrstuden pseye_setreg(sc, 0x23, val);
521 1.7.2.2 wrstuden }
522 1.7.2.2 wrstuden
523 1.7.2.2 wrstuden static uint8_t
524 1.7.2.2 wrstuden pseye_getreg(struct pseye_softc *sc, uint16_t reg)
525 1.7.2.2 wrstuden {
526 1.7.2.2 wrstuden usb_device_request_t req;
527 1.7.2.2 wrstuden usbd_status err;
528 1.7.2.2 wrstuden uint8_t buf;
529 1.7.2.2 wrstuden
530 1.7.2.2 wrstuden req.bmRequestType = UT_READ_VENDOR_DEVICE;
531 1.7.2.2 wrstuden req.bRequest = 1;
532 1.7.2.2 wrstuden USETW(req.wValue, 0x0000);
533 1.7.2.2 wrstuden USETW(req.wIndex, reg);
534 1.7.2.2 wrstuden USETW(req.wLength, 1);
535 1.7.2.2 wrstuden
536 1.7.2.2 wrstuden err = usbd_do_request(sc->sc_udev, &req, &buf);
537 1.7.2.2 wrstuden if (err) {
538 1.7.2.2 wrstuden aprint_error_dev(sc->sc_dev, "couldn't read reg 0x%04x: %s\n",
539 1.7.2.2 wrstuden reg, usbd_errstr(err));
540 1.7.2.2 wrstuden return 0xff;
541 1.7.2.2 wrstuden }
542 1.7.2.2 wrstuden
543 1.7.2.2 wrstuden return buf;
544 1.7.2.2 wrstuden }
545 1.7.2.2 wrstuden
546 1.7.2.2 wrstuden static void
547 1.7.2.2 wrstuden pseye_setreg(struct pseye_softc *sc, uint16_t reg, uint8_t val)
548 1.7.2.2 wrstuden {
549 1.7.2.2 wrstuden usb_device_request_t req;
550 1.7.2.2 wrstuden usbd_status err;
551 1.7.2.2 wrstuden
552 1.7.2.2 wrstuden req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
553 1.7.2.2 wrstuden req.bRequest = 1;
554 1.7.2.2 wrstuden USETW(req.wValue, 0x0000);
555 1.7.2.2 wrstuden USETW(req.wIndex, reg);
556 1.7.2.2 wrstuden USETW(req.wLength, 1);
557 1.7.2.2 wrstuden
558 1.7.2.2 wrstuden err = usbd_do_request(sc->sc_udev, &req, &val);
559 1.7.2.2 wrstuden if (err)
560 1.7.2.2 wrstuden aprint_error_dev(sc->sc_dev, "couldn't write reg 0x%04x: %s\n",
561 1.7.2.2 wrstuden reg, usbd_errstr(err));
562 1.7.2.2 wrstuden }
563 1.7.2.2 wrstuden
564 1.7.2.2 wrstuden static void
565 1.7.2.2 wrstuden pseye_setregv(struct pseye_softc *sc, uint16_t reg, uint8_t val)
566 1.7.2.2 wrstuden {
567 1.7.2.2 wrstuden pseye_setreg(sc, reg, val);
568 1.7.2.2 wrstuden if (pseye_getreg(sc, reg) != val)
569 1.7.2.2 wrstuden aprint_error_dev(sc->sc_dev, "couldn't verify reg 0x%04x\n",
570 1.7.2.2 wrstuden reg);
571 1.7.2.2 wrstuden }
572 1.7.2.2 wrstuden
573 1.7.2.2 wrstuden static void
574 1.7.2.2 wrstuden pseye_sccb_setreg(struct pseye_softc *sc, uint8_t reg, uint8_t val)
575 1.7.2.2 wrstuden {
576 1.7.2.2 wrstuden pseye_setreg(sc, PSEYE_SCCB_SUBADDR, reg);
577 1.7.2.2 wrstuden pseye_setreg(sc, PSEYE_SCCB_WRITE, val);
578 1.7.2.2 wrstuden pseye_setreg(sc, PSEYE_SCCB_OPERATION, PSEYE_SCCB_OP_WRITE_3);
579 1.7.2.2 wrstuden
580 1.7.2.2 wrstuden if (pseye_sccb_status(sc) == false)
581 1.7.2.2 wrstuden aprint_error_dev(sc->sc_dev, "couldn't write sccb reg 0x%04x\n",
582 1.7.2.2 wrstuden reg);
583 1.7.2.2 wrstuden }
584 1.7.2.2 wrstuden
585 1.7.2.2 wrstuden static bool
586 1.7.2.2 wrstuden pseye_sccb_status(struct pseye_softc *sc)
587 1.7.2.2 wrstuden {
588 1.7.2.2 wrstuden int retry = 5;
589 1.7.2.2 wrstuden uint8_t reg;
590 1.7.2.2 wrstuden
591 1.7.2.2 wrstuden while (retry-- >= 0) {
592 1.7.2.2 wrstuden reg = pseye_getreg(sc, PSEYE_SCCB_STATUS);
593 1.7.2.2 wrstuden if (reg == 0x00)
594 1.7.2.2 wrstuden return true;
595 1.7.2.2 wrstuden else if (reg == 0x04)
596 1.7.2.2 wrstuden return false;
597 1.7.2.2 wrstuden }
598 1.7.2.2 wrstuden
599 1.7.2.2 wrstuden aprint_error_dev(sc->sc_dev, "timeout reading sccb status\n");
600 1.7.2.2 wrstuden return false;
601 1.7.2.2 wrstuden }
602 1.7.2.2 wrstuden
603 1.7.2.2 wrstuden static usbd_status
604 1.7.2.2 wrstuden pseye_get_frame(struct pseye_softc *sc)
605 1.7.2.2 wrstuden {
606 1.7.2.2 wrstuden uint32_t len = sc->sc_bulkin_bufferlen;
607 1.7.2.2 wrstuden
608 1.7.2.2 wrstuden if (sc->sc_dying)
609 1.7.2.2 wrstuden return USBD_IOERROR;
610 1.7.2.2 wrstuden
611 1.7.2.2 wrstuden return usbd_bulk_transfer(sc->sc_bulkin_xfer, sc->sc_bulkin_pipe,
612 1.7.2.2 wrstuden USBD_SHORT_XFER_OK|USBD_NO_COPY, 50,
613 1.7.2.2 wrstuden sc->sc_bulkin_buffer, &len, "pseyerb");
614 1.7.2.2 wrstuden }
615 1.7.2.2 wrstuden
616 1.7.2.2 wrstuden static int
617 1.7.2.2 wrstuden pseye_init_pipes(struct pseye_softc *sc)
618 1.7.2.2 wrstuden {
619 1.7.2.2 wrstuden usbd_status err;
620 1.7.2.2 wrstuden
621 1.7.2.2 wrstuden if (sc->sc_dying)
622 1.7.2.2 wrstuden return EIO;
623 1.7.2.2 wrstuden
624 1.7.2.2 wrstuden err = usbd_open_pipe(sc->sc_iface, sc->sc_bulkin, 0,
625 1.7.2.2 wrstuden &sc->sc_bulkin_pipe);
626 1.7.2.2 wrstuden if (err) {
627 1.7.2.2 wrstuden aprint_error_dev(sc->sc_dev, "couldn't open bulk-in pipe: %s\n",
628 1.7.2.2 wrstuden usbd_errstr(err));
629 1.7.2.2 wrstuden return ENOMEM;
630 1.7.2.2 wrstuden }
631 1.7.2.2 wrstuden
632 1.7.2.2 wrstuden pseye_start(sc);
633 1.7.2.2 wrstuden
634 1.7.2.2 wrstuden return 0;
635 1.7.2.2 wrstuden }
636 1.7.2.2 wrstuden
637 1.7.2.2 wrstuden int
638 1.7.2.2 wrstuden pseye_close_pipes(struct pseye_softc *sc)
639 1.7.2.2 wrstuden {
640 1.7.2.2 wrstuden if (sc->sc_bulkin_pipe != NULL) {
641 1.7.2.2 wrstuden usbd_abort_pipe(sc->sc_bulkin_pipe);
642 1.7.2.2 wrstuden usbd_close_pipe(sc->sc_bulkin_pipe);
643 1.7.2.2 wrstuden sc->sc_bulkin_pipe = NULL;
644 1.7.2.2 wrstuden }
645 1.7.2.2 wrstuden
646 1.7.2.2 wrstuden pseye_stop(sc);
647 1.7.2.2 wrstuden
648 1.7.2.2 wrstuden return 0;
649 1.7.2.2 wrstuden }
650 1.7.2.2 wrstuden
651 1.7.2.2 wrstuden static void
652 1.7.2.2 wrstuden pseye_transfer_thread(void *opaque)
653 1.7.2.2 wrstuden {
654 1.7.2.2 wrstuden struct pseye_softc *sc = opaque;
655 1.7.2.2 wrstuden int error;
656 1.7.2.2 wrstuden struct video_payload payload;
657 1.7.2.2 wrstuden
658 1.7.2.2 wrstuden payload.frameno = 0;
659 1.7.2.2 wrstuden
660 1.7.2.2 wrstuden while (sc->sc_running) {
661 1.7.2.2 wrstuden error = pseye_get_frame(sc);
662 1.7.2.2 wrstuden if (error == USBD_NORMAL_COMPLETION) {
663 1.7.2.2 wrstuden payload.data = sc->sc_bulkin_buffer;
664 1.7.2.2 wrstuden payload.size = sc->sc_bulkin_bufferlen;
665 1.7.2.2 wrstuden payload.frameno = (payload.frameno + 1) & 1;
666 1.7.2.2 wrstuden payload.end_of_frame = 1;
667 1.7.2.2 wrstuden video_submit_payload(sc->sc_videodev, &payload);
668 1.7.2.2 wrstuden }
669 1.7.2.2 wrstuden }
670 1.7.2.2 wrstuden
671 1.7.2.2 wrstuden mutex_enter(&sc->sc_mtx);
672 1.7.2.2 wrstuden cv_broadcast(&sc->sc_cv);
673 1.7.2.2 wrstuden mutex_exit(&sc->sc_mtx);
674 1.7.2.2 wrstuden
675 1.7.2.2 wrstuden kthread_exit(0);
676 1.7.2.2 wrstuden }
677 1.7.2.2 wrstuden
678 1.7.2.2 wrstuden /* video(9) API implementations */
679 1.7.2.2 wrstuden static int
680 1.7.2.2 wrstuden pseye_open(void *opaque, int flags)
681 1.7.2.2 wrstuden {
682 1.7.2.2 wrstuden struct pseye_softc *sc = opaque;
683 1.7.2.2 wrstuden
684 1.7.2.2 wrstuden if (sc->sc_dying)
685 1.7.2.2 wrstuden return EIO;
686 1.7.2.2 wrstuden
687 1.7.2.2 wrstuden return pseye_init_pipes(sc);
688 1.7.2.2 wrstuden }
689 1.7.2.2 wrstuden
690 1.7.2.2 wrstuden static void
691 1.7.2.2 wrstuden pseye_close(void *opaque)
692 1.7.2.2 wrstuden {
693 1.7.2.2 wrstuden struct pseye_softc *sc = opaque;
694 1.7.2.2 wrstuden
695 1.7.2.2 wrstuden pseye_close_pipes(sc);
696 1.7.2.2 wrstuden }
697 1.7.2.2 wrstuden
698 1.7.2.2 wrstuden static const char *
699 1.7.2.2 wrstuden pseye_get_devname(void *opaque)
700 1.7.2.2 wrstuden {
701 1.7.2.2 wrstuden return "PLAYSTATION(R) Eye";
702 1.7.2.2 wrstuden }
703 1.7.2.2 wrstuden
704 1.7.2.2 wrstuden static int
705 1.7.2.2 wrstuden pseye_enum_format(void *opaque, uint32_t index, struct video_format *format)
706 1.7.2.2 wrstuden {
707 1.7.2.2 wrstuden if (index != 0)
708 1.7.2.2 wrstuden return EINVAL;
709 1.7.2.2 wrstuden return pseye_get_format(opaque, format);
710 1.7.2.2 wrstuden }
711 1.7.2.2 wrstuden
712 1.7.2.2 wrstuden static int
713 1.7.2.2 wrstuden pseye_get_format(void *opaque, struct video_format *format)
714 1.7.2.2 wrstuden {
715 1.7.2.2 wrstuden format->pixel_format = VIDEO_FORMAT_YUY2; /* XXX actually YUYV */
716 1.7.2.2 wrstuden format->width = 640;
717 1.7.2.2 wrstuden format->height = 480;
718 1.7.2.2 wrstuden format->aspect_x = 4;
719 1.7.2.2 wrstuden format->aspect_y = 3;
720 1.7.2.2 wrstuden format->sample_size = format->width * format->height * 2;
721 1.7.2.2 wrstuden format->stride = format->width * 2;
722 1.7.2.2 wrstuden format->color.primaries = VIDEO_COLOR_PRIMARIES_UNSPECIFIED;
723 1.7.2.2 wrstuden format->color.gamma_function = VIDEO_GAMMA_FUNCTION_UNSPECIFIED;
724 1.7.2.2 wrstuden format->color.matrix_coeff = VIDEO_MATRIX_COEFF_UNSPECIFIED;
725 1.7.2.2 wrstuden format->interlace_flags = VIDEO_INTERLACE_ON;
726 1.7.2.2 wrstuden format->priv = 0;
727 1.7.2.2 wrstuden
728 1.7.2.2 wrstuden return 0;
729 1.7.2.2 wrstuden }
730 1.7.2.2 wrstuden
731 1.7.2.2 wrstuden static int
732 1.7.2.2 wrstuden pseye_set_format(void *opaque, struct video_format *format)
733 1.7.2.2 wrstuden {
734 1.7.2.2 wrstuden #if notyet
735 1.7.2.2 wrstuden if (format->pixel_format != VIDEO_FORMAT_YUYV)
736 1.7.2.2 wrstuden return EINVAL;
737 1.7.2.2 wrstuden if (format->width != 640 || format->height != 480)
738 1.7.2.2 wrstuden return EINVAL;
739 1.7.2.2 wrstuden #endif
740 1.7.2.2 wrstuden /* XXX */
741 1.7.2.2 wrstuden return pseye_get_format(opaque, format);
742 1.7.2.2 wrstuden }
743 1.7.2.2 wrstuden
744 1.7.2.2 wrstuden static int
745 1.7.2.2 wrstuden pseye_try_format(void *opaque, struct video_format *format)
746 1.7.2.2 wrstuden {
747 1.7.2.2 wrstuden return pseye_get_format(opaque, format);
748 1.7.2.2 wrstuden }
749 1.7.2.2 wrstuden
750 1.7.2.2 wrstuden static int
751 1.7.2.2 wrstuden pseye_start_transfer(void *opaque)
752 1.7.2.2 wrstuden {
753 1.7.2.2 wrstuden struct pseye_softc *sc = opaque;
754 1.7.2.2 wrstuden int err = 0;
755 1.7.2.2 wrstuden
756 1.7.2.2 wrstuden mutex_enter(&sc->sc_mtx);
757 1.7.2.2 wrstuden if (sc->sc_running == 0) {
758 1.7.2.2 wrstuden sc->sc_running = 1;
759 1.7.2.2 wrstuden err = kthread_create(PRI_PSEYE, 0, NULL, pseye_transfer_thread,
760 1.7.2.2 wrstuden opaque, NULL, device_xname(sc->sc_dev));
761 1.7.2.2 wrstuden } else
762 1.7.2.2 wrstuden aprint_error_dev(sc->sc_dev, "transfer already in progress\n");
763 1.7.2.2 wrstuden mutex_exit(&sc->sc_mtx);
764 1.7.2.2 wrstuden
765 1.7.2.2 wrstuden return err;
766 1.7.2.2 wrstuden }
767 1.7.2.2 wrstuden
768 1.7.2.2 wrstuden static int
769 1.7.2.2 wrstuden pseye_stop_transfer(void *opaque)
770 1.7.2.2 wrstuden {
771 1.7.2.2 wrstuden struct pseye_softc *sc = opaque;
772 1.7.2.2 wrstuden
773 1.7.2.2 wrstuden mutex_enter(&sc->sc_mtx);
774 1.7.2.2 wrstuden if (sc->sc_running) {
775 1.7.2.2 wrstuden sc->sc_running = 0;
776 1.7.2.2 wrstuden cv_wait_sig(&sc->sc_cv, &sc->sc_mtx);
777 1.7.2.2 wrstuden }
778 1.7.2.2 wrstuden mutex_exit(&sc->sc_mtx);
779 1.7.2.2 wrstuden
780 1.7.2.2 wrstuden return 0;
781 1.7.2.2 wrstuden }
782