27 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
29 #define MODULE_NAME "kinect"
33 #define CTRL_TIMEOUT 500
66 #define MODE_640x480 0x0001
67 #define MODE_640x488 0x0002
68 #define MODE_1280x1024 0x0004
70 #define FORMAT_BAYER 0x0010
71 #define FORMAT_UYVY 0x0020
72 #define FORMAT_Y10B 0x0040
74 #define FPS_HIGH 0x0100
79 .sizeimage = 640 * 480,
83 .bytesperline = 640 * 2,
84 .sizeimage = 640 * 480 * 2,
89 .sizeimage = 1280 * 1024,
93 .bytesperline = 640 * 10 / 8,
94 .sizeimage = 640 * 488 * 10 / 8,
98 .bytesperline = 1280 * 10 / 8,
99 .sizeimage = 1280 * 1024 * 10 / 8,
108 usb_sndctrlpipe(udev, 0),
114 static int kinect_read(
struct usb_device *udev,
uint8_t *data,
uint16_t wLength)
117 usb_rcvctrlpipe(udev, 0),
124 unsigned int cmd_len,
void *replybuf,
unsigned int reply_len)
126 struct sd *
sd = (
struct sd *) gspca_dev;
127 struct usb_device *udev = gspca_dev->
dev;
131 struct cam_hdr *chdr = (
void *)obuf;
132 struct cam_hdr *rhdr = (
void *)ibuf;
134 if (cmd_len & 1 || cmd_len > (0x400 -
sizeof(*chdr))) {
135 pr_err(
"send_cmd: Invalid command length (0x%x)\n", cmd_len);
139 chdr->
magic[0] = 0x47;
140 chdr->
magic[1] = 0x4d;
145 memcpy(obuf+
sizeof(*chdr), cmdbuf, cmd_len);
147 res = kinect_write(udev, obuf, cmd_len +
sizeof(*chdr));
148 PDEBUG(D_USBO,
"Control cmd=%04x tag=%04x len=%04x: %d", cmd,
151 pr_err(
"send_cmd: Output control transfer failed (%d)\n", res);
156 actual_len = kinect_read(udev, ibuf, 0x200);
157 }
while (actual_len == 0);
158 PDEBUG(D_USBO,
"Control reply: %d", res);
159 if (actual_len <
sizeof(*rhdr)) {
160 pr_err(
"send_cmd: Input control transfer failed (%d)\n", res);
163 actual_len -=
sizeof(*rhdr);
165 if (rhdr->
magic[0] != 0x52 || rhdr->
magic[1] != 0x42) {
166 pr_err(
"send_cmd: Bad magic %02x %02x\n",
170 if (rhdr->
cmd != chdr->
cmd) {
171 pr_err(
"send_cmd: Bad cmd %02x != %02x\n",
175 if (rhdr->
tag != chdr->
tag) {
176 pr_err(
"send_cmd: Bad tag %04x != %04x\n",
181 pr_err(
"send_cmd: Bad len %04x != %04x\n",
186 if (actual_len > reply_len) {
187 pr_warn(
"send_cmd: Data buffer is %d bytes long, but got %d bytes\n",
188 reply_len, actual_len);
189 memcpy(replybuf, ibuf+
sizeof(*rhdr), reply_len);
191 memcpy(replybuf, ibuf+
sizeof(*rhdr), actual_len);
199 static int write_register(
struct gspca_dev *gspca_dev,
uint16_t reg,
209 PDEBUG(D_USBO,
"Write Reg 0x%04x <= 0x%02x", reg, data);
210 res = send_cmd(gspca_dev, 0x03, cmd, 4, reply, 4);
214 pr_warn(
"send_cmd returned %d [%04x %04x], 0000 expected\n",
215 res, reply[0], reply[1]);
221 static int sd_config(
struct gspca_dev *gspca_dev,
224 struct sd *sd = (
struct sd *) gspca_dev;
233 cam = &gspca_dev->
cam;
248 static int sd_init(
struct gspca_dev *gspca_dev)
250 PDEBUG(D_PROBE,
"Kinect Camera device.");
255 static int sd_start(
struct gspca_dev *gspca_dev)
263 mode = gspca_dev->
cam.cam_mode[gspca_dev->
curr_mode].priv;
295 write_register(gspca_dev, 0x105, 0x00);
298 write_register(gspca_dev, 0x05, 0x00);
307 if (mode & (FORMAT_Y10B | MODE_1280x1024)) {
308 write_register(gspca_dev, 0x13, 0x01);
309 write_register(gspca_dev, 0x14, 0x1e);
310 write_register(gspca_dev, 0x06, 0x02);
311 write_register(gspca_dev, 0x06, 0x00);
314 write_register(gspca_dev, fmt_reg, fmt_val);
315 write_register(gspca_dev, res_reg, res_val);
316 write_register(gspca_dev, fps_reg, fps_val);
319 write_register(gspca_dev, 0x05, mode_val);
322 write_register(gspca_dev, 0x47, 0x00);
327 static void sd_stopN(
struct gspca_dev *gspca_dev)
330 write_register(gspca_dev, 0x05, 0x00);
333 static void sd_pkt_scan(
struct gspca_dev *gspca_dev,
u8 *
__data,
int len)
335 struct sd *sd = (
struct sd *) gspca_dev;
338 uint8_t *data = __data +
sizeof(*hdr);
339 int datalen = len -
sizeof(*hdr);
348 if (hdr->magic[0] !=
'R' || hdr->magic[1] !=
'B') {
349 pr_warn(
"[Stream %02x] Invalid magic %02x%02x\n",
354 if (hdr->flag == sof)
357 else if (hdr->flag == mof)
360 else if (hdr->flag == eof)
364 pr_warn(
"Packet type not recognized...\n");
374 .pkt_scan = sd_pkt_scan,
383 {USB_DEVICE(0x045e, 0x02ae)},
396 static struct usb_driver sd_driver = {
398 .id_table = device_table,
402 .suspend = gspca_suspend,
403 .resume = gspca_resume,
404 .reset_resume = gspca_resume,