Adam Baker | 27d35fc | 2009-02-06 15:12:46 -0300 | [diff] [blame] | 1 | /* |
| 2 | * SQ905 subdriver |
| 3 | * |
| 4 | * Copyright (C) 2008, 2009 Adam Baker and Theodore Kilgore |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 19 | */ |
| 20 | |
| 21 | /* |
| 22 | * History and Acknowledgments |
| 23 | * |
| 24 | * The original Linux driver for SQ905 based cameras was written by |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 25 | * Marcell Lengyel and furter developed by many other contributors |
Adam Baker | 27d35fc | 2009-02-06 15:12:46 -0300 | [diff] [blame] | 26 | * and is available from http://sourceforge.net/projects/sqcam/ |
| 27 | * |
| 28 | * This driver takes advantage of the reverse engineering work done for |
| 29 | * that driver and for libgphoto2 but shares no code with them. |
| 30 | * |
| 31 | * This driver has used as a base the finepix driver and other gspca |
| 32 | * based drivers and may still contain code fragments taken from those |
| 33 | * drivers. |
| 34 | */ |
| 35 | |
Joe Perches | 133a9fe | 2011-08-21 19:56:57 -0300 | [diff] [blame] | 36 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 37 | |
Adam Baker | 27d35fc | 2009-02-06 15:12:46 -0300 | [diff] [blame] | 38 | #define MODULE_NAME "sq905" |
| 39 | |
| 40 | #include <linux/workqueue.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 41 | #include <linux/slab.h> |
Adam Baker | 27d35fc | 2009-02-06 15:12:46 -0300 | [diff] [blame] | 42 | #include "gspca.h" |
| 43 | |
| 44 | MODULE_AUTHOR("Adam Baker <linux@baker-net.org.uk>, " |
| 45 | "Theodore Kilgore <kilgota@auburn.edu>"); |
| 46 | MODULE_DESCRIPTION("GSPCA/SQ905 USB Camera Driver"); |
| 47 | MODULE_LICENSE("GPL"); |
| 48 | |
| 49 | /* Default timeouts, in ms */ |
| 50 | #define SQ905_CMD_TIMEOUT 500 |
| 51 | #define SQ905_DATA_TIMEOUT 1000 |
| 52 | |
| 53 | /* Maximum transfer size to use. */ |
| 54 | #define SQ905_MAX_TRANSFER 0x8000 |
| 55 | #define FRAME_HEADER_LEN 64 |
| 56 | |
| 57 | /* The known modes, or registers. These go in the "value" slot. */ |
| 58 | |
| 59 | /* 00 is "none" obviously */ |
| 60 | |
| 61 | #define SQ905_BULK_READ 0x03 /* precedes any bulk read */ |
| 62 | #define SQ905_COMMAND 0x06 /* precedes the command codes below */ |
| 63 | #define SQ905_PING 0x07 /* when reading an "idling" command */ |
| 64 | #define SQ905_READ_DONE 0xc0 /* ack bulk read completed */ |
| 65 | |
Adam Baker | 3b27591 | 2009-03-03 20:20:47 -0300 | [diff] [blame] | 66 | /* Any non-zero value in the bottom 2 bits of the 2nd byte of |
| 67 | * the ID appears to indicate the camera can do 640*480. If the |
| 68 | * LSB of that byte is set the image is just upside down, otherwise |
| 69 | * it is rotated 180 degrees. */ |
| 70 | #define SQ905_HIRES_MASK 0x00000300 |
| 71 | #define SQ905_ORIENTATION_MASK 0x00000100 |
| 72 | |
Adam Baker | 27d35fc | 2009-02-06 15:12:46 -0300 | [diff] [blame] | 73 | /* Some command codes. These go in the "index" slot. */ |
| 74 | |
| 75 | #define SQ905_ID 0xf0 /* asks for model string */ |
| 76 | #define SQ905_CONFIG 0x20 /* gets photo alloc. table, not used here */ |
| 77 | #define SQ905_DATA 0x30 /* accesses photo data, not used here */ |
| 78 | #define SQ905_CLEAR 0xa0 /* clear everything */ |
Adam Baker | 3b27591 | 2009-03-03 20:20:47 -0300 | [diff] [blame] | 79 | #define SQ905_CAPTURE_LOW 0x60 /* Starts capture at 160x120 */ |
| 80 | #define SQ905_CAPTURE_MED 0x61 /* Starts capture at 320x240 */ |
| 81 | #define SQ905_CAPTURE_HIGH 0x62 /* Starts capture at 640x480 (some cams only) */ |
Adam Baker | 27d35fc | 2009-02-06 15:12:46 -0300 | [diff] [blame] | 82 | /* note that the capture command also controls the output dimensions */ |
Adam Baker | 27d35fc | 2009-02-06 15:12:46 -0300 | [diff] [blame] | 83 | |
| 84 | /* Structure to hold all of our device specific stuff */ |
| 85 | struct sd { |
| 86 | struct gspca_dev gspca_dev; /* !! must be the first item */ |
| 87 | |
Adam Baker | 27d35fc | 2009-02-06 15:12:46 -0300 | [diff] [blame] | 88 | /* |
| 89 | * Driver stuff |
| 90 | */ |
| 91 | struct work_struct work_struct; |
| 92 | struct workqueue_struct *work_thread; |
| 93 | }; |
| 94 | |
Adam Baker | 3b27591 | 2009-03-03 20:20:47 -0300 | [diff] [blame] | 95 | static struct v4l2_pix_format sq905_mode[] = { |
| 96 | { 160, 120, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE, |
| 97 | .bytesperline = 160, |
| 98 | .sizeimage = 160 * 120, |
| 99 | .colorspace = V4L2_COLORSPACE_SRGB, |
| 100 | .priv = 0}, |
Adam Baker | 27d35fc | 2009-02-06 15:12:46 -0300 | [diff] [blame] | 101 | { 320, 240, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE, |
| 102 | .bytesperline = 320, |
| 103 | .sizeimage = 320 * 240, |
| 104 | .colorspace = V4L2_COLORSPACE_SRGB, |
Adam Baker | 3b27591 | 2009-03-03 20:20:47 -0300 | [diff] [blame] | 105 | .priv = 0}, |
| 106 | { 640, 480, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE, |
| 107 | .bytesperline = 640, |
| 108 | .sizeimage = 640 * 480, |
| 109 | .colorspace = V4L2_COLORSPACE_SRGB, |
Adam Baker | 27d35fc | 2009-02-06 15:12:46 -0300 | [diff] [blame] | 110 | .priv = 0} |
| 111 | }; |
| 112 | |
Adam Baker | 27d35fc | 2009-02-06 15:12:46 -0300 | [diff] [blame] | 113 | /* |
| 114 | * Send a command to the camera. |
| 115 | */ |
| 116 | static int sq905_command(struct gspca_dev *gspca_dev, u16 index) |
| 117 | { |
| 118 | int ret; |
| 119 | |
| 120 | gspca_dev->usb_buf[0] = '\0'; |
| 121 | ret = usb_control_msg(gspca_dev->dev, |
| 122 | usb_sndctrlpipe(gspca_dev->dev, 0), |
| 123 | USB_REQ_SYNCH_FRAME, /* request */ |
| 124 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
| 125 | SQ905_COMMAND, index, gspca_dev->usb_buf, 1, |
| 126 | SQ905_CMD_TIMEOUT); |
| 127 | if (ret < 0) { |
Joe Perches | 133a9fe | 2011-08-21 19:56:57 -0300 | [diff] [blame] | 128 | pr_err("%s: usb_control_msg failed (%d)\n", __func__, ret); |
Adam Baker | 27d35fc | 2009-02-06 15:12:46 -0300 | [diff] [blame] | 129 | return ret; |
| 130 | } |
| 131 | |
| 132 | ret = usb_control_msg(gspca_dev->dev, |
| 133 | usb_sndctrlpipe(gspca_dev->dev, 0), |
| 134 | USB_REQ_SYNCH_FRAME, /* request */ |
| 135 | USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
| 136 | SQ905_PING, 0, gspca_dev->usb_buf, 1, |
| 137 | SQ905_CMD_TIMEOUT); |
| 138 | if (ret < 0) { |
Joe Perches | 133a9fe | 2011-08-21 19:56:57 -0300 | [diff] [blame] | 139 | pr_err("%s: usb_control_msg failed 2 (%d)\n", __func__, ret); |
Adam Baker | 27d35fc | 2009-02-06 15:12:46 -0300 | [diff] [blame] | 140 | return ret; |
| 141 | } |
| 142 | |
| 143 | return 0; |
| 144 | } |
| 145 | |
| 146 | /* |
| 147 | * Acknowledge the end of a frame - see warning on sq905_command. |
| 148 | */ |
| 149 | static int sq905_ack_frame(struct gspca_dev *gspca_dev) |
| 150 | { |
| 151 | int ret; |
| 152 | |
| 153 | gspca_dev->usb_buf[0] = '\0'; |
| 154 | ret = usb_control_msg(gspca_dev->dev, |
| 155 | usb_sndctrlpipe(gspca_dev->dev, 0), |
| 156 | USB_REQ_SYNCH_FRAME, /* request */ |
| 157 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
| 158 | SQ905_READ_DONE, 0, gspca_dev->usb_buf, 1, |
| 159 | SQ905_CMD_TIMEOUT); |
| 160 | if (ret < 0) { |
Joe Perches | 133a9fe | 2011-08-21 19:56:57 -0300 | [diff] [blame] | 161 | pr_err("%s: usb_control_msg failed (%d)\n", __func__, ret); |
Adam Baker | 27d35fc | 2009-02-06 15:12:46 -0300 | [diff] [blame] | 162 | return ret; |
| 163 | } |
| 164 | |
| 165 | return 0; |
| 166 | } |
| 167 | |
| 168 | /* |
| 169 | * request and read a block of data - see warning on sq905_command. |
| 170 | */ |
| 171 | static int |
Hans de Goede | 8519110 | 2009-10-05 05:58:18 -0300 | [diff] [blame] | 172 | sq905_read_data(struct gspca_dev *gspca_dev, u8 *data, int size, int need_lock) |
Adam Baker | 27d35fc | 2009-02-06 15:12:46 -0300 | [diff] [blame] | 173 | { |
| 174 | int ret; |
| 175 | int act_len; |
| 176 | |
| 177 | gspca_dev->usb_buf[0] = '\0'; |
Hans de Goede | 8519110 | 2009-10-05 05:58:18 -0300 | [diff] [blame] | 178 | if (need_lock) |
| 179 | mutex_lock(&gspca_dev->usb_lock); |
Adam Baker | 27d35fc | 2009-02-06 15:12:46 -0300 | [diff] [blame] | 180 | ret = usb_control_msg(gspca_dev->dev, |
| 181 | usb_sndctrlpipe(gspca_dev->dev, 0), |
| 182 | USB_REQ_SYNCH_FRAME, /* request */ |
| 183 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
| 184 | SQ905_BULK_READ, size, gspca_dev->usb_buf, |
| 185 | 1, SQ905_CMD_TIMEOUT); |
Hans de Goede | 8519110 | 2009-10-05 05:58:18 -0300 | [diff] [blame] | 186 | if (need_lock) |
| 187 | mutex_unlock(&gspca_dev->usb_lock); |
Adam Baker | 27d35fc | 2009-02-06 15:12:46 -0300 | [diff] [blame] | 188 | if (ret < 0) { |
Joe Perches | 133a9fe | 2011-08-21 19:56:57 -0300 | [diff] [blame] | 189 | pr_err("%s: usb_control_msg failed (%d)\n", __func__, ret); |
Adam Baker | 27d35fc | 2009-02-06 15:12:46 -0300 | [diff] [blame] | 190 | return ret; |
| 191 | } |
| 192 | ret = usb_bulk_msg(gspca_dev->dev, |
| 193 | usb_rcvbulkpipe(gspca_dev->dev, 0x81), |
| 194 | data, size, &act_len, SQ905_DATA_TIMEOUT); |
| 195 | |
| 196 | /* successful, it returns 0, otherwise negative */ |
| 197 | if (ret < 0 || act_len != size) { |
Joe Perches | 133a9fe | 2011-08-21 19:56:57 -0300 | [diff] [blame] | 198 | pr_err("bulk read fail (%d) len %d/%d\n", ret, act_len, size); |
Adam Baker | 27d35fc | 2009-02-06 15:12:46 -0300 | [diff] [blame] | 199 | return -EIO; |
| 200 | } |
| 201 | return 0; |
| 202 | } |
| 203 | |
| 204 | /* This function is called as a workqueue function and runs whenever the camera |
| 205 | * is streaming data. Because it is a workqueue function it is allowed to sleep |
| 206 | * so we can use synchronous USB calls. To avoid possible collisions with other |
| 207 | * threads attempting to use the camera's USB interface we take the gspca |
| 208 | * usb_lock when performing USB operations. In practice the only thing we need |
| 209 | * to protect against is the usb_set_interface call that gspca makes during |
| 210 | * stream_off as the camera doesn't provide any controls that the user could try |
| 211 | * to change. |
| 212 | */ |
| 213 | static void sq905_dostream(struct work_struct *work) |
| 214 | { |
| 215 | struct sd *dev = container_of(work, struct sd, work_struct); |
| 216 | struct gspca_dev *gspca_dev = &dev->gspca_dev; |
Adam Baker | 27d35fc | 2009-02-06 15:12:46 -0300 | [diff] [blame] | 217 | int bytes_left; /* bytes remaining in current frame. */ |
| 218 | int data_len; /* size to use for the next read. */ |
| 219 | int header_read; /* true if we have already read the frame header. */ |
Adam Baker | 27d35fc | 2009-02-06 15:12:46 -0300 | [diff] [blame] | 220 | int packet_type; |
Jean-Francois Moine | 67e4542 | 2009-03-26 05:03:13 -0300 | [diff] [blame] | 221 | int frame_sz; |
Adam Baker | 27d35fc | 2009-02-06 15:12:46 -0300 | [diff] [blame] | 222 | int ret; |
| 223 | u8 *data; |
| 224 | u8 *buffer; |
| 225 | |
| 226 | buffer = kmalloc(SQ905_MAX_TRANSFER, GFP_KERNEL | GFP_DMA); |
Adam Baker | 27d35fc | 2009-02-06 15:12:46 -0300 | [diff] [blame] | 227 | if (!buffer) { |
Joe Perches | 133a9fe | 2011-08-21 19:56:57 -0300 | [diff] [blame] | 228 | pr_err("Couldn't allocate USB buffer\n"); |
Adam Baker | 27d35fc | 2009-02-06 15:12:46 -0300 | [diff] [blame] | 229 | goto quit_stream; |
| 230 | } |
| 231 | |
Jean-Francois Moine | 67e4542 | 2009-03-26 05:03:13 -0300 | [diff] [blame] | 232 | frame_sz = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].sizeimage |
| 233 | + FRAME_HEADER_LEN; |
| 234 | |
Hans Verkuil | 4ad34da | 2012-05-18 08:40:42 -0300 | [diff] [blame^] | 235 | while (gspca_dev->dev && gspca_dev->streaming) { |
| 236 | #ifdef CONFIG_PM |
| 237 | if (gspca_dev->frozen) |
| 238 | break; |
| 239 | #endif |
Adam Baker | 27d35fc | 2009-02-06 15:12:46 -0300 | [diff] [blame] | 240 | /* request some data and then read it until we have |
| 241 | * a complete frame. */ |
Jean-Francois Moine | 67e4542 | 2009-03-26 05:03:13 -0300 | [diff] [blame] | 242 | bytes_left = frame_sz; |
Adam Baker | 27d35fc | 2009-02-06 15:12:46 -0300 | [diff] [blame] | 243 | header_read = 0; |
Adam Baker | 27d35fc | 2009-02-06 15:12:46 -0300 | [diff] [blame] | 244 | |
Hans de Goede | 8519110 | 2009-10-05 05:58:18 -0300 | [diff] [blame] | 245 | /* Note we do not check for gspca_dev->streaming here, as |
| 246 | we must finish reading an entire frame, otherwise the |
| 247 | next time we stream we start reading in the middle of a |
| 248 | frame. */ |
Hans Verkuil | 254902b | 2012-05-06 09:28:22 -0300 | [diff] [blame] | 249 | while (bytes_left > 0 && gspca_dev->dev) { |
Adam Baker | 27d35fc | 2009-02-06 15:12:46 -0300 | [diff] [blame] | 250 | data_len = bytes_left > SQ905_MAX_TRANSFER ? |
| 251 | SQ905_MAX_TRANSFER : bytes_left; |
Hans de Goede | 8519110 | 2009-10-05 05:58:18 -0300 | [diff] [blame] | 252 | ret = sq905_read_data(gspca_dev, buffer, data_len, 1); |
Adam Baker | 27d35fc | 2009-02-06 15:12:46 -0300 | [diff] [blame] | 253 | if (ret < 0) |
| 254 | goto quit_stream; |
Hans de Goede | 8519110 | 2009-10-05 05:58:18 -0300 | [diff] [blame] | 255 | PDEBUG(D_PACK, |
Adam Baker | 27d35fc | 2009-02-06 15:12:46 -0300 | [diff] [blame] | 256 | "Got %d bytes out of %d for frame", |
| 257 | data_len, bytes_left); |
| 258 | bytes_left -= data_len; |
| 259 | data = buffer; |
| 260 | if (!header_read) { |
| 261 | packet_type = FIRST_PACKET; |
| 262 | /* The first 64 bytes of each frame are |
| 263 | * a header full of FF 00 bytes */ |
| 264 | data += FRAME_HEADER_LEN; |
| 265 | data_len -= FRAME_HEADER_LEN; |
| 266 | header_read = 1; |
| 267 | } else if (bytes_left == 0) { |
| 268 | packet_type = LAST_PACKET; |
| 269 | } else { |
| 270 | packet_type = INTER_PACKET; |
| 271 | } |
Jean-Francois Moine | 76dd272 | 2009-11-13 09:21:03 -0300 | [diff] [blame] | 272 | gspca_frame_add(gspca_dev, packet_type, |
| 273 | data, data_len); |
| 274 | /* If entire frame fits in one packet we still |
| 275 | need to add a LAST_PACKET */ |
| 276 | if (packet_type == FIRST_PACKET && |
| 277 | bytes_left == 0) |
| 278 | gspca_frame_add(gspca_dev, LAST_PACKET, |
| 279 | NULL, 0); |
Adam Baker | 27d35fc | 2009-02-06 15:12:46 -0300 | [diff] [blame] | 280 | } |
Hans Verkuil | 254902b | 2012-05-06 09:28:22 -0300 | [diff] [blame] | 281 | if (gspca_dev->dev) { |
Hans de Goede | 8519110 | 2009-10-05 05:58:18 -0300 | [diff] [blame] | 282 | /* acknowledge the frame */ |
| 283 | mutex_lock(&gspca_dev->usb_lock); |
| 284 | ret = sq905_ack_frame(gspca_dev); |
| 285 | mutex_unlock(&gspca_dev->usb_lock); |
| 286 | if (ret < 0) |
| 287 | goto quit_stream; |
| 288 | } |
Adam Baker | 27d35fc | 2009-02-06 15:12:46 -0300 | [diff] [blame] | 289 | } |
| 290 | quit_stream: |
Hans Verkuil | 254902b | 2012-05-06 09:28:22 -0300 | [diff] [blame] | 291 | if (gspca_dev->dev) { |
Hans de Goede | 8519110 | 2009-10-05 05:58:18 -0300 | [diff] [blame] | 292 | mutex_lock(&gspca_dev->usb_lock); |
Adam Baker | 27d35fc | 2009-02-06 15:12:46 -0300 | [diff] [blame] | 293 | sq905_command(gspca_dev, SQ905_CLEAR); |
Hans de Goede | 8519110 | 2009-10-05 05:58:18 -0300 | [diff] [blame] | 294 | mutex_unlock(&gspca_dev->usb_lock); |
| 295 | } |
Adam Baker | 27d35fc | 2009-02-06 15:12:46 -0300 | [diff] [blame] | 296 | kfree(buffer); |
| 297 | } |
| 298 | |
| 299 | /* This function is called at probe time just before sd_init */ |
| 300 | static int sd_config(struct gspca_dev *gspca_dev, |
| 301 | const struct usb_device_id *id) |
| 302 | { |
| 303 | struct cam *cam = &gspca_dev->cam; |
| 304 | struct sd *dev = (struct sd *) gspca_dev; |
| 305 | |
Adam Baker | 27d35fc | 2009-02-06 15:12:46 -0300 | [diff] [blame] | 306 | /* We don't use the buffer gspca allocates so make it small. */ |
Jean-Francois Moine | 6929dc6 | 2009-04-21 13:45:56 -0300 | [diff] [blame] | 307 | cam->bulk = 1; |
Adam Baker | 27d35fc | 2009-02-06 15:12:46 -0300 | [diff] [blame] | 308 | cam->bulk_size = 64; |
| 309 | |
| 310 | INIT_WORK(&dev->work_struct, sq905_dostream); |
| 311 | |
| 312 | return 0; |
| 313 | } |
| 314 | |
| 315 | /* called on streamoff with alt==0 and on disconnect */ |
| 316 | /* the usb_lock is held at entry - restore on exit */ |
| 317 | static void sd_stop0(struct gspca_dev *gspca_dev) |
| 318 | { |
| 319 | struct sd *dev = (struct sd *) gspca_dev; |
| 320 | |
| 321 | /* wait for the work queue to terminate */ |
| 322 | mutex_unlock(&gspca_dev->usb_lock); |
| 323 | /* This waits for sq905_dostream to finish */ |
| 324 | destroy_workqueue(dev->work_thread); |
| 325 | dev->work_thread = NULL; |
| 326 | mutex_lock(&gspca_dev->usb_lock); |
| 327 | } |
| 328 | |
| 329 | /* this function is called at probe and resume time */ |
| 330 | static int sd_init(struct gspca_dev *gspca_dev) |
| 331 | { |
Adam Baker | 27d35fc | 2009-02-06 15:12:46 -0300 | [diff] [blame] | 332 | u32 ident; |
| 333 | int ret; |
| 334 | |
| 335 | /* connect to the camera and read |
| 336 | * the model ID and process that and put it away. |
| 337 | */ |
| 338 | ret = sq905_command(gspca_dev, SQ905_CLEAR); |
| 339 | if (ret < 0) |
| 340 | return ret; |
| 341 | ret = sq905_command(gspca_dev, SQ905_ID); |
| 342 | if (ret < 0) |
| 343 | return ret; |
Hans de Goede | 8519110 | 2009-10-05 05:58:18 -0300 | [diff] [blame] | 344 | ret = sq905_read_data(gspca_dev, gspca_dev->usb_buf, 4, 0); |
Adam Baker | 27d35fc | 2009-02-06 15:12:46 -0300 | [diff] [blame] | 345 | if (ret < 0) |
| 346 | return ret; |
Adam Baker | 3b27591 | 2009-03-03 20:20:47 -0300 | [diff] [blame] | 347 | /* usb_buf is allocated with kmalloc so is aligned. |
| 348 | * Camera model number is the right way round if we assume this |
| 349 | * reverse engineered ID is supposed to be big endian. */ |
| 350 | ident = be32_to_cpup((__be32 *)gspca_dev->usb_buf); |
Adam Baker | 27d35fc | 2009-02-06 15:12:46 -0300 | [diff] [blame] | 351 | ret = sq905_command(gspca_dev, SQ905_CLEAR); |
| 352 | if (ret < 0) |
| 353 | return ret; |
Adam Baker | 3b27591 | 2009-03-03 20:20:47 -0300 | [diff] [blame] | 354 | PDEBUG(D_CONF, "SQ905 camera ID %08x detected", ident); |
| 355 | gspca_dev->cam.cam_mode = sq905_mode; |
| 356 | gspca_dev->cam.nmodes = ARRAY_SIZE(sq905_mode); |
| 357 | if (!(ident & SQ905_HIRES_MASK)) |
| 358 | gspca_dev->cam.nmodes--; |
Adam Baker | dfa76fa | 2009-03-29 19:17:10 -0300 | [diff] [blame] | 359 | |
| 360 | if (ident & SQ905_ORIENTATION_MASK) |
| 361 | gspca_dev->cam.input_flags = V4L2_IN_ST_VFLIP; |
| 362 | else |
| 363 | gspca_dev->cam.input_flags = V4L2_IN_ST_VFLIP | |
| 364 | V4L2_IN_ST_HFLIP; |
Adam Baker | 27d35fc | 2009-02-06 15:12:46 -0300 | [diff] [blame] | 365 | return 0; |
| 366 | } |
| 367 | |
| 368 | /* Set up for getting frames. */ |
| 369 | static int sd_start(struct gspca_dev *gspca_dev) |
| 370 | { |
| 371 | struct sd *dev = (struct sd *) gspca_dev; |
| 372 | int ret; |
| 373 | |
| 374 | /* "Open the shutter" and set size, to start capture */ |
Jean-Francois Moine | 67e4542 | 2009-03-26 05:03:13 -0300 | [diff] [blame] | 375 | switch (gspca_dev->curr_mode) { |
| 376 | default: |
| 377 | /* case 2: */ |
Adam Baker | 3b27591 | 2009-03-03 20:20:47 -0300 | [diff] [blame] | 378 | PDEBUG(D_STREAM, "Start streaming at high resolution"); |
Adam Baker | 3b27591 | 2009-03-03 20:20:47 -0300 | [diff] [blame] | 379 | ret = sq905_command(&dev->gspca_dev, SQ905_CAPTURE_HIGH); |
| 380 | break; |
Jean-Francois Moine | 67e4542 | 2009-03-26 05:03:13 -0300 | [diff] [blame] | 381 | case 1: |
Adam Baker | 3b27591 | 2009-03-03 20:20:47 -0300 | [diff] [blame] | 382 | PDEBUG(D_STREAM, "Start streaming at medium resolution"); |
Adam Baker | 3b27591 | 2009-03-03 20:20:47 -0300 | [diff] [blame] | 383 | ret = sq905_command(&dev->gspca_dev, SQ905_CAPTURE_MED); |
| 384 | break; |
Jean-Francois Moine | 67e4542 | 2009-03-26 05:03:13 -0300 | [diff] [blame] | 385 | case 0: |
Adam Baker | 3b27591 | 2009-03-03 20:20:47 -0300 | [diff] [blame] | 386 | PDEBUG(D_STREAM, "Start streaming at low resolution"); |
| 387 | ret = sq905_command(&dev->gspca_dev, SQ905_CAPTURE_LOW); |
| 388 | } |
| 389 | |
Adam Baker | 27d35fc | 2009-02-06 15:12:46 -0300 | [diff] [blame] | 390 | if (ret < 0) { |
| 391 | PDEBUG(D_ERR, "Start streaming command failed"); |
| 392 | return ret; |
| 393 | } |
Adam Baker | 27d35fc | 2009-02-06 15:12:46 -0300 | [diff] [blame] | 394 | /* Start the workqueue function to do the streaming */ |
| 395 | dev->work_thread = create_singlethread_workqueue(MODULE_NAME); |
| 396 | queue_work(dev->work_thread, &dev->work_struct); |
| 397 | |
| 398 | return 0; |
| 399 | } |
| 400 | |
| 401 | /* Table of supported USB devices */ |
Jean-François Moine | 95c967c | 2011-01-13 05:20:29 -0300 | [diff] [blame] | 402 | static const struct usb_device_id device_table[] = { |
Adam Baker | 27d35fc | 2009-02-06 15:12:46 -0300 | [diff] [blame] | 403 | {USB_DEVICE(0x2770, 0x9120)}, |
| 404 | {} |
| 405 | }; |
| 406 | |
| 407 | MODULE_DEVICE_TABLE(usb, device_table); |
| 408 | |
| 409 | /* sub-driver description */ |
| 410 | static const struct sd_desc sd_desc = { |
| 411 | .name = MODULE_NAME, |
| 412 | .config = sd_config, |
| 413 | .init = sd_init, |
| 414 | .start = sd_start, |
| 415 | .stop0 = sd_stop0, |
| 416 | }; |
| 417 | |
| 418 | /* -- device connect -- */ |
| 419 | static int sd_probe(struct usb_interface *intf, |
| 420 | const struct usb_device_id *id) |
| 421 | { |
| 422 | return gspca_dev_probe(intf, id, |
| 423 | &sd_desc, |
| 424 | sizeof(struct sd), |
| 425 | THIS_MODULE); |
| 426 | } |
| 427 | |
| 428 | static struct usb_driver sd_driver = { |
| 429 | .name = MODULE_NAME, |
| 430 | .id_table = device_table, |
| 431 | .probe = sd_probe, |
| 432 | .disconnect = gspca_disconnect, |
| 433 | #ifdef CONFIG_PM |
| 434 | .suspend = gspca_suspend, |
| 435 | .resume = gspca_resume, |
| 436 | #endif |
| 437 | }; |
| 438 | |
Greg Kroah-Hartman | ecb3b2b | 2011-11-18 09:46:12 -0800 | [diff] [blame] | 439 | module_usb_driver(sd_driver); |