pseye.c revision 1.7.2.5 1 1.7.2.5 skrll /* $NetBSD: pseye.c,v 1.7.2.5 2008/10/10 22:33:10 skrll 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.5 skrll __KERNEL_RCSID(0, "$NetBSD: pseye.c,v 1.7.2.5 2008/10/10 22:33:10 skrll 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.5 skrll static int
157 1.7.2.5 skrll pseye_match(device_t parent, cfdata_t match, void *opaque)
158 1.7.2.2 wrstuden {
159 1.7.2.5 skrll struct usbif_attach_arg *uaa = opaque;
160 1.7.2.2 wrstuden
161 1.7.2.2 wrstuden if (uaa->class != UICLASS_VENDOR)
162 1.7.2.2 wrstuden return UMATCH_NONE;
163 1.7.2.2 wrstuden
164 1.7.2.2 wrstuden if (uaa->vendor == USB_VENDOR_OMNIVISION2) {
165 1.7.2.2 wrstuden switch (uaa->product) {
166 1.7.2.2 wrstuden case USB_PRODUCT_OMNIVISION2_PSEYE:
167 1.7.2.2 wrstuden if (uaa->ifaceno != 0)
168 1.7.2.2 wrstuden return UMATCH_NONE;
169 1.7.2.2 wrstuden return UMATCH_VENDOR_PRODUCT;
170 1.7.2.2 wrstuden }
171 1.7.2.2 wrstuden }
172 1.7.2.2 wrstuden
173 1.7.2.2 wrstuden return UMATCH_NONE;
174 1.7.2.2 wrstuden }
175 1.7.2.2 wrstuden
176 1.7.2.5 skrll static void
177 1.7.2.5 skrll pseye_attach(device_t parent, device_t self, void *opaque)
178 1.7.2.2 wrstuden {
179 1.7.2.5 skrll struct pseye_softc *sc = device_private(self);
180 1.7.2.5 skrll struct usbif_attach_arg *uaa = opaque;
181 1.7.2.2 wrstuden usbd_device_handle dev = uaa->device;
182 1.7.2.2 wrstuden usb_interface_descriptor_t *id = NULL;
183 1.7.2.2 wrstuden usb_endpoint_descriptor_t *ed = NULL, *ed_bulkin = NULL;
184 1.7.2.2 wrstuden char *devinfo;
185 1.7.2.2 wrstuden int i;
186 1.7.2.2 wrstuden
187 1.7.2.2 wrstuden devinfo = usbd_devinfo_alloc(dev, 0);
188 1.7.2.5 skrll aprint_naive("\n");
189 1.7.2.5 skrll aprint_normal(": %s\n", devinfo);
190 1.7.2.2 wrstuden usbd_devinfo_free(devinfo);
191 1.7.2.2 wrstuden
192 1.7.2.2 wrstuden sc->sc_dev = self;
193 1.7.2.2 wrstuden sc->sc_udev = dev;
194 1.7.2.2 wrstuden sc->sc_iface = uaa->iface;
195 1.7.2.2 wrstuden sc->sc_bulkin_bufferlen = PSEYE_BULKIN_BUFLEN;
196 1.7.2.2 wrstuden
197 1.7.2.2 wrstuden sc->sc_dying = sc->sc_running = 0;
198 1.7.2.4 wrstuden cv_init(&sc->sc_cv, device_xname(self));
199 1.7.2.2 wrstuden mutex_init(&sc->sc_mtx, MUTEX_DEFAULT, IPL_NONE);
200 1.7.2.2 wrstuden
201 1.7.2.2 wrstuden id = usbd_get_interface_descriptor(sc->sc_iface);
202 1.7.2.2 wrstuden if (id == NULL) {
203 1.7.2.2 wrstuden aprint_error_dev(self, "failed to get interface descriptor\n");
204 1.7.2.2 wrstuden sc->sc_dying = 1;
205 1.7.2.5 skrll return;
206 1.7.2.2 wrstuden }
207 1.7.2.2 wrstuden
208 1.7.2.2 wrstuden for (i = 0; i < id->bNumEndpoints; i++) {
209 1.7.2.2 wrstuden ed = usbd_interface2endpoint_descriptor(sc->sc_iface, i);
210 1.7.2.2 wrstuden if (ed == NULL) {
211 1.7.2.4 wrstuden aprint_error_dev(self, "couldn't get ep %d\n", i);
212 1.7.2.2 wrstuden sc->sc_dying = 1;
213 1.7.2.5 skrll return;
214 1.7.2.2 wrstuden }
215 1.7.2.2 wrstuden
216 1.7.2.2 wrstuden if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
217 1.7.2.2 wrstuden UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
218 1.7.2.2 wrstuden ed_bulkin = ed;
219 1.7.2.2 wrstuden break;
220 1.7.2.2 wrstuden }
221 1.7.2.2 wrstuden }
222 1.7.2.2 wrstuden
223 1.7.2.2 wrstuden if (ed_bulkin == NULL) {
224 1.7.2.4 wrstuden aprint_error_dev(self, "no bulk-in endpoint found\n");
225 1.7.2.2 wrstuden sc->sc_dying = 1;
226 1.7.2.5 skrll return;
227 1.7.2.2 wrstuden }
228 1.7.2.2 wrstuden
229 1.7.2.2 wrstuden sc->sc_bulkin = ed_bulkin->bEndpointAddress;
230 1.7.2.2 wrstuden
231 1.7.2.2 wrstuden sc->sc_bulkin_xfer = usbd_alloc_xfer(sc->sc_udev);
232 1.7.2.2 wrstuden if (sc->sc_bulkin_xfer == NULL) {
233 1.7.2.2 wrstuden sc->sc_dying = 1;
234 1.7.2.5 skrll return;
235 1.7.2.2 wrstuden }
236 1.7.2.2 wrstuden sc->sc_bulkin_buffer = usbd_alloc_buffer(sc->sc_bulkin_xfer,
237 1.7.2.2 wrstuden sc->sc_bulkin_bufferlen);
238 1.7.2.2 wrstuden if (sc->sc_bulkin_buffer == NULL) {
239 1.7.2.2 wrstuden usbd_free_xfer(sc->sc_bulkin_xfer);
240 1.7.2.2 wrstuden sc->sc_bulkin_xfer = NULL;
241 1.7.2.2 wrstuden sc->sc_dying = 1;
242 1.7.2.5 skrll return;
243 1.7.2.2 wrstuden }
244 1.7.2.2 wrstuden
245 1.7.2.2 wrstuden pseye_init(sc);
246 1.7.2.2 wrstuden
247 1.7.2.4 wrstuden if (!pmf_device_register(self, NULL, NULL))
248 1.7.2.4 wrstuden aprint_error_dev(self, "couldn't establish power handler\n");
249 1.7.2.4 wrstuden
250 1.7.2.4 wrstuden sc->sc_videodev = video_attach_mi(&pseye_hw_if, self);
251 1.7.2.2 wrstuden if (sc->sc_videodev == NULL) {
252 1.7.2.4 wrstuden aprint_error_dev(self, "couldn't attach video layer\n");
253 1.7.2.2 wrstuden sc->sc_dying = 1;
254 1.7.2.5 skrll return;
255 1.7.2.2 wrstuden }
256 1.7.2.2 wrstuden
257 1.7.2.2 wrstuden usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, sc->sc_udev,
258 1.7.2.4 wrstuden USBDEV(self));
259 1.7.2.2 wrstuden
260 1.7.2.2 wrstuden }
261 1.7.2.2 wrstuden
262 1.7.2.5 skrll static int
263 1.7.2.5 skrll pseye_detach(device_t self, int flags)
264 1.7.2.2 wrstuden {
265 1.7.2.5 skrll struct pseye_softc *sc = device_private(self);
266 1.7.2.2 wrstuden
267 1.7.2.2 wrstuden sc->sc_dying = 1;
268 1.7.2.2 wrstuden
269 1.7.2.4 wrstuden pmf_device_deregister(self);
270 1.7.2.4 wrstuden
271 1.7.2.2 wrstuden if (sc->sc_videodev != NULL) {
272 1.7.2.2 wrstuden config_detach(sc->sc_videodev, flags);
273 1.7.2.2 wrstuden sc->sc_videodev = NULL;
274 1.7.2.2 wrstuden }
275 1.7.2.2 wrstuden
276 1.7.2.2 wrstuden if (sc->sc_bulkin_xfer != NULL) {
277 1.7.2.2 wrstuden usbd_free_xfer(sc->sc_bulkin_xfer);
278 1.7.2.2 wrstuden sc->sc_bulkin_xfer = NULL;
279 1.7.2.2 wrstuden }
280 1.7.2.2 wrstuden
281 1.7.2.2 wrstuden if (sc->sc_bulkin_pipe != NULL) {
282 1.7.2.2 wrstuden usbd_abort_pipe(sc->sc_bulkin_pipe);
283 1.7.2.2 wrstuden sc->sc_bulkin_pipe = NULL;
284 1.7.2.2 wrstuden }
285 1.7.2.2 wrstuden
286 1.7.2.2 wrstuden mutex_enter(&sc->sc_mtx);
287 1.7.2.2 wrstuden if (sc->sc_running) {
288 1.7.2.2 wrstuden sc->sc_running = 0;
289 1.7.2.2 wrstuden cv_wait_sig(&sc->sc_cv, &sc->sc_mtx);
290 1.7.2.2 wrstuden }
291 1.7.2.2 wrstuden mutex_exit(&sc->sc_mtx);
292 1.7.2.2 wrstuden
293 1.7.2.2 wrstuden cv_destroy(&sc->sc_cv);
294 1.7.2.2 wrstuden mutex_destroy(&sc->sc_mtx);
295 1.7.2.2 wrstuden
296 1.7.2.2 wrstuden usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_udev,
297 1.7.2.2 wrstuden USBDEV(sc->sc_dev));
298 1.7.2.2 wrstuden
299 1.7.2.2 wrstuden return 0;
300 1.7.2.2 wrstuden }
301 1.7.2.2 wrstuden
302 1.7.2.2 wrstuden int
303 1.7.2.2 wrstuden pseye_activate(device_ptr_t self, enum devact act)
304 1.7.2.2 wrstuden {
305 1.7.2.2 wrstuden struct pseye_softc *sc = device_private(self);
306 1.7.2.2 wrstuden int rv;
307 1.7.2.2 wrstuden
308 1.7.2.2 wrstuden rv = 0;
309 1.7.2.2 wrstuden
310 1.7.2.2 wrstuden switch (act) {
311 1.7.2.2 wrstuden case DVACT_ACTIVATE:
312 1.7.2.2 wrstuden break;
313 1.7.2.2 wrstuden case DVACT_DEACTIVATE:
314 1.7.2.2 wrstuden sc->sc_dying = 1;
315 1.7.2.2 wrstuden break;
316 1.7.2.2 wrstuden }
317 1.7.2.2 wrstuden
318 1.7.2.2 wrstuden return rv;
319 1.7.2.2 wrstuden }
320 1.7.2.2 wrstuden
321 1.7.2.2 wrstuden static void
322 1.7.2.2 wrstuden pseye_childdet(device_t self, device_t child)
323 1.7.2.2 wrstuden {
324 1.7.2.2 wrstuden struct pseye_softc *sc = device_private(self);
325 1.7.2.2 wrstuden
326 1.7.2.2 wrstuden if (sc->sc_videodev) {
327 1.7.2.2 wrstuden KASSERT(sc->sc_videodev == child);
328 1.7.2.2 wrstuden sc->sc_videodev = NULL;
329 1.7.2.2 wrstuden }
330 1.7.2.2 wrstuden }
331 1.7.2.2 wrstuden
332 1.7.2.2 wrstuden /*
333 1.7.2.2 wrstuden * Device access
334 1.7.2.2 wrstuden */
335 1.7.2.2 wrstuden
336 1.7.2.2 wrstuden static void
337 1.7.2.2 wrstuden pseye_init(struct pseye_softc *sc)
338 1.7.2.2 wrstuden {
339 1.7.2.2 wrstuden pseye_sccb_init(sc);
340 1.7.2.2 wrstuden
341 1.7.2.2 wrstuden pseye_setregv(sc, 0xc2, 0x0c);
342 1.7.2.2 wrstuden pseye_setregv(sc, 0x88, 0xf8);
343 1.7.2.2 wrstuden pseye_setregv(sc, 0xc3, 0x69);
344 1.7.2.2 wrstuden pseye_setregv(sc, 0x89, 0xff);
345 1.7.2.2 wrstuden pseye_setregv(sc, 0x76, 0x03);
346 1.7.2.2 wrstuden pseye_setregv(sc, 0x92, 0x01);
347 1.7.2.2 wrstuden pseye_setregv(sc, 0x93, 0x18);
348 1.7.2.2 wrstuden pseye_setregv(sc, 0x94, 0x10);
349 1.7.2.2 wrstuden pseye_setregv(sc, 0x95, 0x10);
350 1.7.2.2 wrstuden pseye_setregv(sc, 0xe2, 0x00);
351 1.7.2.2 wrstuden pseye_setregv(sc, 0xe7, 0x3e);
352 1.7.2.2 wrstuden
353 1.7.2.2 wrstuden pseye_setreg(sc, 0x1c, 0x0a);
354 1.7.2.2 wrstuden pseye_setreg(sc, 0x1d, 0x22);
355 1.7.2.2 wrstuden pseye_setreg(sc, 0x1d, 0x06);
356 1.7.2.2 wrstuden pseye_setregv(sc, 0x96, 0x00);
357 1.7.2.2 wrstuden
358 1.7.2.2 wrstuden pseye_setreg(sc, 0x97, 0x20);
359 1.7.2.2 wrstuden pseye_setreg(sc, 0x97, 0x20);
360 1.7.2.2 wrstuden pseye_setreg(sc, 0x97, 0x20);
361 1.7.2.2 wrstuden pseye_setreg(sc, 0x97, 0x0a);
362 1.7.2.2 wrstuden pseye_setreg(sc, 0x97, 0x3f);
363 1.7.2.2 wrstuden pseye_setreg(sc, 0x97, 0x4a);
364 1.7.2.2 wrstuden pseye_setreg(sc, 0x97, 0x20);
365 1.7.2.2 wrstuden pseye_setreg(sc, 0x97, 0x15);
366 1.7.2.2 wrstuden pseye_setreg(sc, 0x97, 0x0b);
367 1.7.2.2 wrstuden
368 1.7.2.2 wrstuden pseye_setregv(sc, 0x8e, 0x40);
369 1.7.2.2 wrstuden pseye_setregv(sc, 0x1f, 0x81);
370 1.7.2.2 wrstuden pseye_setregv(sc, 0x34, 0x05);
371 1.7.2.2 wrstuden pseye_setregv(sc, 0xe3, 0x04);
372 1.7.2.2 wrstuden pseye_setregv(sc, 0x88, 0x00);
373 1.7.2.2 wrstuden pseye_setregv(sc, 0x89, 0x00);
374 1.7.2.2 wrstuden pseye_setregv(sc, 0x76, 0x00);
375 1.7.2.2 wrstuden pseye_setregv(sc, 0xe7, 0x2e);
376 1.7.2.2 wrstuden pseye_setregv(sc, 0x31, 0xf9);
377 1.7.2.2 wrstuden pseye_setregv(sc, 0x25, 0x42);
378 1.7.2.2 wrstuden pseye_setregv(sc, 0x21, 0xf0);
379 1.7.2.2 wrstuden
380 1.7.2.2 wrstuden pseye_setreg(sc, 0x1c, 0x00);
381 1.7.2.2 wrstuden pseye_setreg(sc, 0x1d, 0x40);
382 1.7.2.2 wrstuden pseye_setreg(sc, 0x1d, 0x02);
383 1.7.2.2 wrstuden pseye_setreg(sc, 0x1d, 0x00);
384 1.7.2.2 wrstuden pseye_setreg(sc, 0x1d, 0x02);
385 1.7.2.2 wrstuden pseye_setreg(sc, 0x1d, 0x57);
386 1.7.2.2 wrstuden pseye_setreg(sc, 0x1d, 0xff);
387 1.7.2.2 wrstuden
388 1.7.2.2 wrstuden pseye_setregv(sc, 0x8d, 0x1c);
389 1.7.2.2 wrstuden pseye_setregv(sc, 0x8e, 0x80);
390 1.7.2.2 wrstuden pseye_setregv(sc, 0xe5, 0x04);
391 1.7.2.2 wrstuden
392 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x12, 0x80);
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 pseye_sccb_setreg(sc, 0x11, 0x01);
397 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x11, 0x01);
398 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x11, 0x01);
399 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x11, 0x01);
400 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x11, 0x01);
401 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x11, 0x01);
402 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x11, 0x01);
403 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x11, 0x01);
404 1.7.2.2 wrstuden
405 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x3d, 0x03);
406 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x17, 0x26);
407 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x18, 0xa0);
408 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x19, 0x07);
409 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x1a, 0xf0);
410 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x32, 0x00);
411 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x29, 0xa0);
412 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x2c, 0xf0);
413 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x65, 0x20);
414 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x11, 0x01);
415 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x42, 0x7f);
416 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x63, 0xe0);
417 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x64, 0xff);
418 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x66, 0x00);
419 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x13, 0xf0);
420 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x0d, 0x41);
421 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x0f, 0xc5);
422 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x14, 0x11);
423 1.7.2.2 wrstuden
424 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x22, 0x7f);
425 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x23, 0x03);
426 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x24, 0x40);
427 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x25, 0x30);
428 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x26, 0xa1);
429 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x2a, 0x00);
430 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x2b, 0x00);
431 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x6b, 0xaa);
432 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x13, 0xff);
433 1.7.2.2 wrstuden
434 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x90, 0x05);
435 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x91, 0x01);
436 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x92, 0x03);
437 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x93, 0x00);
438 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x94, 0x60);
439 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x95, 0x3c);
440 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x96, 0x24);
441 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x97, 0x1e);
442 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x98, 0x62);
443 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x99, 0x80);
444 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x9a, 0x1e);
445 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x9b, 0x08);
446 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x9c, 0x20);
447 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x9e, 0x81);
448 1.7.2.2 wrstuden
449 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0xa6, 0x04);
450 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x7e, 0x0c);
451 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x7f, 0x16);
452 1.7.2.2 wrstuden
453 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x80, 0x2a);
454 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x81, 0x4e);
455 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x82, 0x61);
456 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x83, 0x6f);
457 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x84, 0x7b);
458 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x85, 0x86);
459 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x86, 0x8e);
460 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x87, 0x97);
461 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x88, 0xa4);
462 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x89, 0xaf);
463 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x8a, 0xc5);
464 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x8b, 0xd7);
465 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x8c, 0xe8);
466 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x8d, 0x20);
467 1.7.2.2 wrstuden
468 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x0c, 0x90);
469 1.7.2.2 wrstuden
470 1.7.2.2 wrstuden pseye_setregv(sc, 0xc0, 0x50);
471 1.7.2.2 wrstuden pseye_setregv(sc, 0xc1, 0x3c);
472 1.7.2.2 wrstuden pseye_setregv(sc, 0xc2, 0x0c);
473 1.7.2.2 wrstuden
474 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x2b, 0x00);
475 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x22, 0x7f);
476 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x23, 0x03);
477 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x11, 0x01);
478 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x0c, 0xd0);
479 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x64, 0xff);
480 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x0d, 0x41);
481 1.7.2.2 wrstuden
482 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x14, 0x41);
483 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x0e, 0xcd);
484 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0xac, 0xbf);
485 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x8e, 0x00);
486 1.7.2.2 wrstuden pseye_sccb_setreg(sc, 0x0c, 0xd0);
487 1.7.2.2 wrstuden
488 1.7.2.2 wrstuden pseye_stop(sc);
489 1.7.2.2 wrstuden }
490 1.7.2.2 wrstuden
491 1.7.2.2 wrstuden static void
492 1.7.2.2 wrstuden pseye_sccb_init(struct pseye_softc *sc)
493 1.7.2.2 wrstuden {
494 1.7.2.2 wrstuden pseye_setregv(sc, 0xe7, 0x3a);
495 1.7.2.2 wrstuden pseye_setreg(sc, PSEYE_SCCB_ADDRESS, 0x60);
496 1.7.2.2 wrstuden pseye_setreg(sc, PSEYE_SCCB_ADDRESS, 0x60);
497 1.7.2.2 wrstuden pseye_setreg(sc, PSEYE_SCCB_ADDRESS, 0x60);
498 1.7.2.2 wrstuden pseye_setreg(sc, PSEYE_SCCB_ADDRESS, 0x42);
499 1.7.2.2 wrstuden }
500 1.7.2.2 wrstuden
501 1.7.2.2 wrstuden static void
502 1.7.2.2 wrstuden pseye_stop(struct pseye_softc *sc)
503 1.7.2.2 wrstuden {
504 1.7.2.2 wrstuden pseye_led(sc, false);
505 1.7.2.2 wrstuden pseye_setreg(sc, 0xe0, 0x09);
506 1.7.2.2 wrstuden }
507 1.7.2.2 wrstuden
508 1.7.2.2 wrstuden static void
509 1.7.2.2 wrstuden pseye_start(struct pseye_softc *sc)
510 1.7.2.2 wrstuden {
511 1.7.2.2 wrstuden pseye_led(sc, true);
512 1.7.2.2 wrstuden pseye_setreg(sc, 0xe0, 0x00);
513 1.7.2.2 wrstuden }
514 1.7.2.2 wrstuden
515 1.7.2.2 wrstuden static void
516 1.7.2.2 wrstuden pseye_led(struct pseye_softc *sc, bool enabled)
517 1.7.2.2 wrstuden {
518 1.7.2.2 wrstuden uint8_t val;
519 1.7.2.2 wrstuden
520 1.7.2.2 wrstuden val = pseye_getreg(sc, 0x21);
521 1.7.2.2 wrstuden pseye_setreg(sc, 0x21, val | 0x80);
522 1.7.2.2 wrstuden
523 1.7.2.2 wrstuden val = pseye_getreg(sc, 0x23);
524 1.7.2.2 wrstuden if (enabled == true)
525 1.7.2.2 wrstuden val |= 0x80;
526 1.7.2.2 wrstuden else
527 1.7.2.2 wrstuden val &= ~0x80;
528 1.7.2.2 wrstuden pseye_setreg(sc, 0x23, val);
529 1.7.2.2 wrstuden }
530 1.7.2.2 wrstuden
531 1.7.2.2 wrstuden static uint8_t
532 1.7.2.2 wrstuden pseye_getreg(struct pseye_softc *sc, uint16_t reg)
533 1.7.2.2 wrstuden {
534 1.7.2.2 wrstuden usb_device_request_t req;
535 1.7.2.2 wrstuden usbd_status err;
536 1.7.2.2 wrstuden uint8_t buf;
537 1.7.2.2 wrstuden
538 1.7.2.2 wrstuden req.bmRequestType = UT_READ_VENDOR_DEVICE;
539 1.7.2.2 wrstuden req.bRequest = 1;
540 1.7.2.2 wrstuden USETW(req.wValue, 0x0000);
541 1.7.2.2 wrstuden USETW(req.wIndex, reg);
542 1.7.2.2 wrstuden USETW(req.wLength, 1);
543 1.7.2.2 wrstuden
544 1.7.2.2 wrstuden err = usbd_do_request(sc->sc_udev, &req, &buf);
545 1.7.2.2 wrstuden if (err) {
546 1.7.2.2 wrstuden aprint_error_dev(sc->sc_dev, "couldn't read reg 0x%04x: %s\n",
547 1.7.2.2 wrstuden reg, usbd_errstr(err));
548 1.7.2.2 wrstuden return 0xff;
549 1.7.2.2 wrstuden }
550 1.7.2.2 wrstuden
551 1.7.2.2 wrstuden return buf;
552 1.7.2.2 wrstuden }
553 1.7.2.2 wrstuden
554 1.7.2.2 wrstuden static void
555 1.7.2.2 wrstuden pseye_setreg(struct pseye_softc *sc, uint16_t reg, uint8_t val)
556 1.7.2.2 wrstuden {
557 1.7.2.2 wrstuden usb_device_request_t req;
558 1.7.2.2 wrstuden usbd_status err;
559 1.7.2.2 wrstuden
560 1.7.2.2 wrstuden req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
561 1.7.2.2 wrstuden req.bRequest = 1;
562 1.7.2.2 wrstuden USETW(req.wValue, 0x0000);
563 1.7.2.2 wrstuden USETW(req.wIndex, reg);
564 1.7.2.2 wrstuden USETW(req.wLength, 1);
565 1.7.2.2 wrstuden
566 1.7.2.2 wrstuden err = usbd_do_request(sc->sc_udev, &req, &val);
567 1.7.2.2 wrstuden if (err)
568 1.7.2.2 wrstuden aprint_error_dev(sc->sc_dev, "couldn't write reg 0x%04x: %s\n",
569 1.7.2.2 wrstuden reg, usbd_errstr(err));
570 1.7.2.2 wrstuden }
571 1.7.2.2 wrstuden
572 1.7.2.2 wrstuden static void
573 1.7.2.2 wrstuden pseye_setregv(struct pseye_softc *sc, uint16_t reg, uint8_t val)
574 1.7.2.2 wrstuden {
575 1.7.2.2 wrstuden pseye_setreg(sc, reg, val);
576 1.7.2.2 wrstuden if (pseye_getreg(sc, reg) != val)
577 1.7.2.2 wrstuden aprint_error_dev(sc->sc_dev, "couldn't verify reg 0x%04x\n",
578 1.7.2.2 wrstuden reg);
579 1.7.2.2 wrstuden }
580 1.7.2.2 wrstuden
581 1.7.2.2 wrstuden static void
582 1.7.2.2 wrstuden pseye_sccb_setreg(struct pseye_softc *sc, uint8_t reg, uint8_t val)
583 1.7.2.2 wrstuden {
584 1.7.2.2 wrstuden pseye_setreg(sc, PSEYE_SCCB_SUBADDR, reg);
585 1.7.2.2 wrstuden pseye_setreg(sc, PSEYE_SCCB_WRITE, val);
586 1.7.2.2 wrstuden pseye_setreg(sc, PSEYE_SCCB_OPERATION, PSEYE_SCCB_OP_WRITE_3);
587 1.7.2.2 wrstuden
588 1.7.2.2 wrstuden if (pseye_sccb_status(sc) == false)
589 1.7.2.2 wrstuden aprint_error_dev(sc->sc_dev, "couldn't write sccb reg 0x%04x\n",
590 1.7.2.2 wrstuden reg);
591 1.7.2.2 wrstuden }
592 1.7.2.2 wrstuden
593 1.7.2.2 wrstuden static bool
594 1.7.2.2 wrstuden pseye_sccb_status(struct pseye_softc *sc)
595 1.7.2.2 wrstuden {
596 1.7.2.2 wrstuden int retry = 5;
597 1.7.2.2 wrstuden uint8_t reg;
598 1.7.2.2 wrstuden
599 1.7.2.2 wrstuden while (retry-- >= 0) {
600 1.7.2.2 wrstuden reg = pseye_getreg(sc, PSEYE_SCCB_STATUS);
601 1.7.2.2 wrstuden if (reg == 0x00)
602 1.7.2.2 wrstuden return true;
603 1.7.2.2 wrstuden else if (reg == 0x04)
604 1.7.2.2 wrstuden return false;
605 1.7.2.2 wrstuden }
606 1.7.2.2 wrstuden
607 1.7.2.2 wrstuden aprint_error_dev(sc->sc_dev, "timeout reading sccb status\n");
608 1.7.2.2 wrstuden return false;
609 1.7.2.2 wrstuden }
610 1.7.2.2 wrstuden
611 1.7.2.2 wrstuden static usbd_status
612 1.7.2.2 wrstuden pseye_get_frame(struct pseye_softc *sc)
613 1.7.2.2 wrstuden {
614 1.7.2.2 wrstuden uint32_t len = sc->sc_bulkin_bufferlen;
615 1.7.2.2 wrstuden
616 1.7.2.2 wrstuden if (sc->sc_dying)
617 1.7.2.2 wrstuden return USBD_IOERROR;
618 1.7.2.2 wrstuden
619 1.7.2.2 wrstuden return usbd_bulk_transfer(sc->sc_bulkin_xfer, sc->sc_bulkin_pipe,
620 1.7.2.2 wrstuden USBD_SHORT_XFER_OK|USBD_NO_COPY, 50,
621 1.7.2.2 wrstuden sc->sc_bulkin_buffer, &len, "pseyerb");
622 1.7.2.2 wrstuden }
623 1.7.2.2 wrstuden
624 1.7.2.2 wrstuden static int
625 1.7.2.2 wrstuden pseye_init_pipes(struct pseye_softc *sc)
626 1.7.2.2 wrstuden {
627 1.7.2.2 wrstuden usbd_status err;
628 1.7.2.2 wrstuden
629 1.7.2.2 wrstuden if (sc->sc_dying)
630 1.7.2.2 wrstuden return EIO;
631 1.7.2.2 wrstuden
632 1.7.2.2 wrstuden err = usbd_open_pipe(sc->sc_iface, sc->sc_bulkin, 0,
633 1.7.2.2 wrstuden &sc->sc_bulkin_pipe);
634 1.7.2.2 wrstuden if (err) {
635 1.7.2.2 wrstuden aprint_error_dev(sc->sc_dev, "couldn't open bulk-in pipe: %s\n",
636 1.7.2.2 wrstuden usbd_errstr(err));
637 1.7.2.2 wrstuden return ENOMEM;
638 1.7.2.2 wrstuden }
639 1.7.2.2 wrstuden
640 1.7.2.2 wrstuden pseye_start(sc);
641 1.7.2.2 wrstuden
642 1.7.2.2 wrstuden return 0;
643 1.7.2.2 wrstuden }
644 1.7.2.2 wrstuden
645 1.7.2.2 wrstuden int
646 1.7.2.2 wrstuden pseye_close_pipes(struct pseye_softc *sc)
647 1.7.2.2 wrstuden {
648 1.7.2.2 wrstuden if (sc->sc_bulkin_pipe != NULL) {
649 1.7.2.2 wrstuden usbd_abort_pipe(sc->sc_bulkin_pipe);
650 1.7.2.2 wrstuden usbd_close_pipe(sc->sc_bulkin_pipe);
651 1.7.2.2 wrstuden sc->sc_bulkin_pipe = NULL;
652 1.7.2.2 wrstuden }
653 1.7.2.2 wrstuden
654 1.7.2.2 wrstuden pseye_stop(sc);
655 1.7.2.2 wrstuden
656 1.7.2.2 wrstuden return 0;
657 1.7.2.2 wrstuden }
658 1.7.2.2 wrstuden
659 1.7.2.2 wrstuden static void
660 1.7.2.2 wrstuden pseye_transfer_thread(void *opaque)
661 1.7.2.2 wrstuden {
662 1.7.2.2 wrstuden struct pseye_softc *sc = opaque;
663 1.7.2.2 wrstuden int error;
664 1.7.2.2 wrstuden struct video_payload payload;
665 1.7.2.2 wrstuden
666 1.7.2.2 wrstuden payload.frameno = 0;
667 1.7.2.2 wrstuden
668 1.7.2.2 wrstuden while (sc->sc_running) {
669 1.7.2.2 wrstuden error = pseye_get_frame(sc);
670 1.7.2.2 wrstuden if (error == USBD_NORMAL_COMPLETION) {
671 1.7.2.2 wrstuden payload.data = sc->sc_bulkin_buffer;
672 1.7.2.2 wrstuden payload.size = sc->sc_bulkin_bufferlen;
673 1.7.2.2 wrstuden payload.frameno = (payload.frameno + 1) & 1;
674 1.7.2.2 wrstuden payload.end_of_frame = 1;
675 1.7.2.2 wrstuden video_submit_payload(sc->sc_videodev, &payload);
676 1.7.2.2 wrstuden }
677 1.7.2.2 wrstuden }
678 1.7.2.2 wrstuden
679 1.7.2.2 wrstuden mutex_enter(&sc->sc_mtx);
680 1.7.2.2 wrstuden cv_broadcast(&sc->sc_cv);
681 1.7.2.2 wrstuden mutex_exit(&sc->sc_mtx);
682 1.7.2.2 wrstuden
683 1.7.2.2 wrstuden kthread_exit(0);
684 1.7.2.2 wrstuden }
685 1.7.2.2 wrstuden
686 1.7.2.2 wrstuden /* video(9) API implementations */
687 1.7.2.2 wrstuden static int
688 1.7.2.2 wrstuden pseye_open(void *opaque, int flags)
689 1.7.2.2 wrstuden {
690 1.7.2.2 wrstuden struct pseye_softc *sc = opaque;
691 1.7.2.2 wrstuden
692 1.7.2.2 wrstuden if (sc->sc_dying)
693 1.7.2.2 wrstuden return EIO;
694 1.7.2.2 wrstuden
695 1.7.2.2 wrstuden return pseye_init_pipes(sc);
696 1.7.2.2 wrstuden }
697 1.7.2.2 wrstuden
698 1.7.2.2 wrstuden static void
699 1.7.2.2 wrstuden pseye_close(void *opaque)
700 1.7.2.2 wrstuden {
701 1.7.2.2 wrstuden struct pseye_softc *sc = opaque;
702 1.7.2.2 wrstuden
703 1.7.2.2 wrstuden pseye_close_pipes(sc);
704 1.7.2.2 wrstuden }
705 1.7.2.2 wrstuden
706 1.7.2.2 wrstuden static const char *
707 1.7.2.2 wrstuden pseye_get_devname(void *opaque)
708 1.7.2.2 wrstuden {
709 1.7.2.2 wrstuden return "PLAYSTATION(R) Eye";
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_enum_format(void *opaque, uint32_t index, struct video_format *format)
714 1.7.2.2 wrstuden {
715 1.7.2.2 wrstuden if (index != 0)
716 1.7.2.2 wrstuden return EINVAL;
717 1.7.2.2 wrstuden return pseye_get_format(opaque, format);
718 1.7.2.2 wrstuden }
719 1.7.2.2 wrstuden
720 1.7.2.2 wrstuden static int
721 1.7.2.2 wrstuden pseye_get_format(void *opaque, struct video_format *format)
722 1.7.2.2 wrstuden {
723 1.7.2.2 wrstuden format->pixel_format = VIDEO_FORMAT_YUY2; /* XXX actually YUYV */
724 1.7.2.2 wrstuden format->width = 640;
725 1.7.2.2 wrstuden format->height = 480;
726 1.7.2.2 wrstuden format->aspect_x = 4;
727 1.7.2.2 wrstuden format->aspect_y = 3;
728 1.7.2.2 wrstuden format->sample_size = format->width * format->height * 2;
729 1.7.2.2 wrstuden format->stride = format->width * 2;
730 1.7.2.2 wrstuden format->color.primaries = VIDEO_COLOR_PRIMARIES_UNSPECIFIED;
731 1.7.2.2 wrstuden format->color.gamma_function = VIDEO_GAMMA_FUNCTION_UNSPECIFIED;
732 1.7.2.2 wrstuden format->color.matrix_coeff = VIDEO_MATRIX_COEFF_UNSPECIFIED;
733 1.7.2.2 wrstuden format->interlace_flags = VIDEO_INTERLACE_ON;
734 1.7.2.2 wrstuden format->priv = 0;
735 1.7.2.2 wrstuden
736 1.7.2.2 wrstuden return 0;
737 1.7.2.2 wrstuden }
738 1.7.2.2 wrstuden
739 1.7.2.2 wrstuden static int
740 1.7.2.2 wrstuden pseye_set_format(void *opaque, struct video_format *format)
741 1.7.2.2 wrstuden {
742 1.7.2.2 wrstuden #if notyet
743 1.7.2.2 wrstuden if (format->pixel_format != VIDEO_FORMAT_YUYV)
744 1.7.2.2 wrstuden return EINVAL;
745 1.7.2.2 wrstuden if (format->width != 640 || format->height != 480)
746 1.7.2.2 wrstuden return EINVAL;
747 1.7.2.2 wrstuden #endif
748 1.7.2.2 wrstuden /* XXX */
749 1.7.2.2 wrstuden return pseye_get_format(opaque, format);
750 1.7.2.2 wrstuden }
751 1.7.2.2 wrstuden
752 1.7.2.2 wrstuden static int
753 1.7.2.2 wrstuden pseye_try_format(void *opaque, struct video_format *format)
754 1.7.2.2 wrstuden {
755 1.7.2.2 wrstuden return pseye_get_format(opaque, format);
756 1.7.2.2 wrstuden }
757 1.7.2.2 wrstuden
758 1.7.2.2 wrstuden static int
759 1.7.2.2 wrstuden pseye_start_transfer(void *opaque)
760 1.7.2.2 wrstuden {
761 1.7.2.2 wrstuden struct pseye_softc *sc = opaque;
762 1.7.2.2 wrstuden int err = 0;
763 1.7.2.2 wrstuden
764 1.7.2.2 wrstuden mutex_enter(&sc->sc_mtx);
765 1.7.2.2 wrstuden if (sc->sc_running == 0) {
766 1.7.2.2 wrstuden sc->sc_running = 1;
767 1.7.2.2 wrstuden err = kthread_create(PRI_PSEYE, 0, NULL, pseye_transfer_thread,
768 1.7.2.2 wrstuden opaque, NULL, device_xname(sc->sc_dev));
769 1.7.2.2 wrstuden } else
770 1.7.2.2 wrstuden aprint_error_dev(sc->sc_dev, "transfer already in progress\n");
771 1.7.2.2 wrstuden mutex_exit(&sc->sc_mtx);
772 1.7.2.2 wrstuden
773 1.7.2.2 wrstuden return err;
774 1.7.2.2 wrstuden }
775 1.7.2.2 wrstuden
776 1.7.2.2 wrstuden static int
777 1.7.2.2 wrstuden pseye_stop_transfer(void *opaque)
778 1.7.2.2 wrstuden {
779 1.7.2.2 wrstuden struct pseye_softc *sc = opaque;
780 1.7.2.2 wrstuden
781 1.7.2.2 wrstuden mutex_enter(&sc->sc_mtx);
782 1.7.2.2 wrstuden if (sc->sc_running) {
783 1.7.2.2 wrstuden sc->sc_running = 0;
784 1.7.2.2 wrstuden cv_wait_sig(&sc->sc_cv, &sc->sc_mtx);
785 1.7.2.2 wrstuden }
786 1.7.2.2 wrstuden mutex_exit(&sc->sc_mtx);
787 1.7.2.2 wrstuden
788 1.7.2.2 wrstuden return 0;
789 1.7.2.2 wrstuden }
790