aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntonio Ospite <ao2@ao2.it>2014-06-25 05:27:57 -0400
committerMauro Carvalho Chehab <m.chehab@samsung.com>2014-07-04 13:51:01 -0400
commitc87c0f079cf8c9c346adbedd367ba53ad0afaded (patch)
treeb1d1f07ba9e379c59381c195e9b101411ea10f9a
parent2fe152451df0ead7e1ca14c0c6210b13226feafb (diff)
[media] gspca_kinect: add support for the depth stream
Add support for the depth stream at 10bpp, for now use a 'depth_mode' command line parameter to switch between video and depth mode. Signed-off-by: Alexander Sosna <alexander@xxor.de> Signed-off-by: Antonio Ospite <ao2@ao2.it> Signed-off-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
-rw-r--r--drivers/media/usb/gspca/kinect.c98
1 files changed, 87 insertions, 11 deletions
diff --git a/drivers/media/usb/gspca/kinect.c b/drivers/media/usb/gspca/kinect.c
index 081f05162809..45bc1f51c5d8 100644
--- a/drivers/media/usb/gspca/kinect.c
+++ b/drivers/media/usb/gspca/kinect.c
@@ -36,6 +36,8 @@ MODULE_AUTHOR("Antonio Ospite <ospite@studenti.unina.it>");
36MODULE_DESCRIPTION("GSPCA/Kinect Sensor Device USB Camera Driver"); 36MODULE_DESCRIPTION("GSPCA/Kinect Sensor Device USB Camera Driver");
37MODULE_LICENSE("GPL"); 37MODULE_LICENSE("GPL");
38 38
39static bool depth_mode;
40
39struct pkt_hdr { 41struct pkt_hdr {
40 uint8_t magic[2]; 42 uint8_t magic[2];
41 uint8_t pad; 43 uint8_t pad;
@@ -73,6 +75,14 @@ struct sd {
73 75
74#define FPS_HIGH 0x0100 76#define FPS_HIGH 0x0100
75 77
78static const struct v4l2_pix_format depth_camera_mode[] = {
79 {640, 480, V4L2_PIX_FMT_Y10BPACK, V4L2_FIELD_NONE,
80 .bytesperline = 640 * 10 / 8,
81 .sizeimage = 640 * 480 * 10 / 8,
82 .colorspace = V4L2_COLORSPACE_SRGB,
83 .priv = MODE_640x488 | FORMAT_Y10B},
84};
85
76static const struct v4l2_pix_format video_camera_mode[] = { 86static const struct v4l2_pix_format video_camera_mode[] = {
77 {640, 480, V4L2_PIX_FMT_SGRBG8, V4L2_FIELD_NONE, 87 {640, 480, V4L2_PIX_FMT_SGRBG8, V4L2_FIELD_NONE,
78 .bytesperline = 640, 88 .bytesperline = 640,
@@ -219,7 +229,7 @@ static int write_register(struct gspca_dev *gspca_dev, uint16_t reg,
219} 229}
220 230
221/* this function is called at probe time */ 231/* this function is called at probe time */
222static int sd_config(struct gspca_dev *gspca_dev, 232static int sd_config_video(struct gspca_dev *gspca_dev,
223 const struct usb_device_id *id) 233 const struct usb_device_id *id)
224{ 234{
225 struct sd *sd = (struct sd *) gspca_dev; 235 struct sd *sd = (struct sd *) gspca_dev;
@@ -227,8 +237,6 @@ static int sd_config(struct gspca_dev *gspca_dev,
227 237
228 sd->cam_tag = 0; 238 sd->cam_tag = 0;
229 239
230 /* Only video stream is supported for now,
231 * which has stream flag = 0x80 */
232 sd->stream_flag = 0x80; 240 sd->stream_flag = 0x80;
233 241
234 cam = &gspca_dev->cam; 242 cam = &gspca_dev->cam;
@@ -236,6 +244,8 @@ static int sd_config(struct gspca_dev *gspca_dev,
236 cam->cam_mode = video_camera_mode; 244 cam->cam_mode = video_camera_mode;
237 cam->nmodes = ARRAY_SIZE(video_camera_mode); 245 cam->nmodes = ARRAY_SIZE(video_camera_mode);
238 246
247 gspca_dev->xfer_ep = 0x81;
248
239#if 0 249#if 0
240 /* Setting those values is not needed for video stream */ 250 /* Setting those values is not needed for video stream */
241 cam->npkt = 15; 251 cam->npkt = 15;
@@ -245,6 +255,26 @@ static int sd_config(struct gspca_dev *gspca_dev,
245 return 0; 255 return 0;
246} 256}
247 257
258static int sd_config_depth(struct gspca_dev *gspca_dev,
259 const struct usb_device_id *id)
260{
261 struct sd *sd = (struct sd *) gspca_dev;
262 struct cam *cam;
263
264 sd->cam_tag = 0;
265
266 sd->stream_flag = 0x70;
267
268 cam = &gspca_dev->cam;
269
270 cam->cam_mode = depth_camera_mode;
271 cam->nmodes = ARRAY_SIZE(depth_camera_mode);
272
273 gspca_dev->xfer_ep = 0x82;
274
275 return 0;
276}
277
248/* this function is called at probe and resume time */ 278/* this function is called at probe and resume time */
249static int sd_init(struct gspca_dev *gspca_dev) 279static int sd_init(struct gspca_dev *gspca_dev)
250{ 280{
@@ -253,7 +283,7 @@ static int sd_init(struct gspca_dev *gspca_dev)
253 return 0; 283 return 0;
254} 284}
255 285
256static int sd_start(struct gspca_dev *gspca_dev) 286static int sd_start_video(struct gspca_dev *gspca_dev)
257{ 287{
258 int mode; 288 int mode;
259 uint8_t fmt_reg, fmt_val; 289 uint8_t fmt_reg, fmt_val;
@@ -325,12 +355,39 @@ static int sd_start(struct gspca_dev *gspca_dev)
325 return 0; 355 return 0;
326} 356}
327 357
328static void sd_stopN(struct gspca_dev *gspca_dev) 358static int sd_start_depth(struct gspca_dev *gspca_dev)
359{
360 /* turn off IR-reset function */
361 write_register(gspca_dev, 0x105, 0x00);
362
363 /* reset depth stream */
364 write_register(gspca_dev, 0x06, 0x00);
365 /* Depth Stream Format 0x03: 11 bit stream | 0x02: 10 bit */
366 write_register(gspca_dev, 0x12, 0x02);
367 /* Depth Stream Resolution 1: standard (640x480) */
368 write_register(gspca_dev, 0x13, 0x01);
369 /* Depth Framerate / 0x1e (30): 30 fps */
370 write_register(gspca_dev, 0x14, 0x1e);
371 /* Depth Stream Control / 2: Open Depth Stream */
372 write_register(gspca_dev, 0x06, 0x02);
373 /* disable depth hflip / LSB = 0: Smoothing Disabled */
374 write_register(gspca_dev, 0x17, 0x00);
375
376 return 0;
377}
378
379static void sd_stopN_video(struct gspca_dev *gspca_dev)
329{ 380{
330 /* reset video stream */ 381 /* reset video stream */
331 write_register(gspca_dev, 0x05, 0x00); 382 write_register(gspca_dev, 0x05, 0x00);
332} 383}
333 384
385static void sd_stopN_depth(struct gspca_dev *gspca_dev)
386{
387 /* reset depth stream */
388 write_register(gspca_dev, 0x06, 0x00);
389}
390
334static void sd_pkt_scan(struct gspca_dev *gspca_dev, u8 *__data, int len) 391static void sd_pkt_scan(struct gspca_dev *gspca_dev, u8 *__data, int len)
335{ 392{
336 struct sd *sd = (struct sd *) gspca_dev; 393 struct sd *sd = (struct sd *) gspca_dev;
@@ -366,12 +423,24 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev, u8 *__data, int len)
366} 423}
367 424
368/* sub-driver description */ 425/* sub-driver description */
369static const struct sd_desc sd_desc = { 426static const struct sd_desc sd_desc_video = {
370 .name = MODULE_NAME, 427 .name = MODULE_NAME,
371 .config = sd_config, 428 .config = sd_config_video,
372 .init = sd_init, 429 .init = sd_init,
373 .start = sd_start, 430 .start = sd_start_video,
374 .stopN = sd_stopN, 431 .stopN = sd_stopN_video,
432 .pkt_scan = sd_pkt_scan,
433 /*
434 .get_streamparm = sd_get_streamparm,
435 .set_streamparm = sd_set_streamparm,
436 */
437};
438static const struct sd_desc sd_desc_depth = {
439 .name = MODULE_NAME,
440 .config = sd_config_depth,
441 .init = sd_init,
442 .start = sd_start_depth,
443 .stopN = sd_stopN_depth,
375 .pkt_scan = sd_pkt_scan, 444 .pkt_scan = sd_pkt_scan,
376 /* 445 /*
377 .get_streamparm = sd_get_streamparm, 446 .get_streamparm = sd_get_streamparm,
@@ -391,8 +460,12 @@ MODULE_DEVICE_TABLE(usb, device_table);
391/* -- device connect -- */ 460/* -- device connect -- */
392static int sd_probe(struct usb_interface *intf, const struct usb_device_id *id) 461static int sd_probe(struct usb_interface *intf, const struct usb_device_id *id)
393{ 462{
394 return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd), 463 if (depth_mode)
395 THIS_MODULE); 464 return gspca_dev_probe(intf, id, &sd_desc_depth,
465 sizeof(struct sd), THIS_MODULE);
466 else
467 return gspca_dev_probe(intf, id, &sd_desc_video,
468 sizeof(struct sd), THIS_MODULE);
396} 469}
397 470
398static struct usb_driver sd_driver = { 471static struct usb_driver sd_driver = {
@@ -408,3 +481,6 @@ static struct usb_driver sd_driver = {
408}; 481};
409 482
410module_usb_driver(sd_driver); 483module_usb_driver(sd_driver);
484
485module_param(depth_mode, bool, 0644);
486MODULE_PARM_DESC(depth_mode, "0=video 1=depth");