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