blob: 5ab3f7e12760dcf4c8490fb77d9cdeac46ec9c2e [file] [log] [blame]
Theodore Kilgore3040b042009-08-03 04:13:23 -03001/*
2 * Jeilinj subdriver
3 *
4 * Supports some Jeilin dual-mode cameras which use bulk transport and
5 * download raw JPEG data.
6 *
7 * Copyright (C) 2009 Theodore Kilgore
Patrice Chotard5396e622011-04-18 17:42:06 -03008 *
9 * Sportscam DV15 support and control settings are
Patrice Chotardc3d86922011-04-18 17:37:06 -030010 * Copyright (C) 2011 Patrice Chotard
Theodore Kilgore3040b042009-08-03 04:13:23 -030011 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 */
26
Joe Perches133a9fe2011-08-21 19:56:57 -030027#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
28
Theodore Kilgore3040b042009-08-03 04:13:23 -030029#define MODULE_NAME "jeilinj"
30
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090031#include <linux/slab.h>
Theodore Kilgore3040b042009-08-03 04:13:23 -030032#include "gspca.h"
33#include "jpeg.h"
34
35MODULE_AUTHOR("Theodore Kilgore <kilgota@auburn.edu>");
36MODULE_DESCRIPTION("GSPCA/JEILINJ USB Camera Driver");
37MODULE_LICENSE("GPL");
38
39/* Default timeouts, in ms */
40#define JEILINJ_CMD_TIMEOUT 500
Patrice Chotard713b4662011-04-18 17:40:54 -030041#define JEILINJ_CMD_DELAY 160
Theodore Kilgore3040b042009-08-03 04:13:23 -030042#define JEILINJ_DATA_TIMEOUT 1000
43
44/* Maximum transfer size to use. */
45#define JEILINJ_MAX_TRANSFER 0x200
Theodore Kilgore3040b042009-08-03 04:13:23 -030046#define FRAME_HEADER_LEN 0x10
Patrice Chotardc3d86922011-04-18 17:37:06 -030047#define FRAME_START 0xFFFFFFFF
Theodore Kilgore3040b042009-08-03 04:13:23 -030048
Patrice Chotard713b4662011-04-18 17:40:54 -030049enum {
50 SAKAR_57379,
51 SPORTSCAM_DV15,
52};
Patrice Chotard5396e622011-04-18 17:42:06 -030053
54#define CAMQUALITY_MIN 0 /* highest cam quality */
55#define CAMQUALITY_MAX 97 /* lowest cam quality */
56
57enum e_ctrl {
58 LIGHTFREQ,
59 AUTOGAIN,
60 RED,
61 GREEN,
62 BLUE,
63 NCTRLS /* number of controls */
64};
65
Theodore Kilgore3040b042009-08-03 04:13:23 -030066/* Structure to hold all of our device specific stuff */
67struct sd {
68 struct gspca_dev gspca_dev; /* !! must be the first item */
Patrice Chotard5396e622011-04-18 17:42:06 -030069 struct gspca_ctrl ctrls[NCTRLS];
Patrice Chotardc3d86922011-04-18 17:37:06 -030070 int blocks_left;
Theodore Kilgore3040b042009-08-03 04:13:23 -030071 const struct v4l2_pix_format *cap_mode;
72 /* Driver stuff */
Patrice Chotard713b4662011-04-18 17:40:54 -030073 u8 type;
Theodore Kilgore3040b042009-08-03 04:13:23 -030074 u8 quality; /* image quality */
Patrice Chotard5396e622011-04-18 17:42:06 -030075#define QUALITY_MIN 35
76#define QUALITY_MAX 85
77#define QUALITY_DEF 85
Jean-François Moine9a731a32010-06-04 05:26:42 -030078 u8 jpeg_hdr[JPEG_HDR_SZ];
Theodore Kilgore3040b042009-08-03 04:13:23 -030079};
80
Patrice Chotardc3d86922011-04-18 17:37:06 -030081struct jlj_command {
82 unsigned char instruction[2];
83 unsigned char ack_wanted;
Patrice Chotard713b4662011-04-18 17:40:54 -030084 unsigned char delay;
Patrice Chotardc3d86922011-04-18 17:37:06 -030085};
Theodore Kilgore3040b042009-08-03 04:13:23 -030086
87/* AFAICT these cameras will only do 320x240. */
88static struct v4l2_pix_format jlj_mode[] = {
89 { 320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
90 .bytesperline = 320,
91 .sizeimage = 320 * 240,
92 .colorspace = V4L2_COLORSPACE_JPEG,
Patrice Chotard6f8efcf2011-04-18 17:39:38 -030093 .priv = 0},
94 { 640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
95 .bytesperline = 640,
96 .sizeimage = 640 * 480,
97 .colorspace = V4L2_COLORSPACE_JPEG,
Theodore Kilgore3040b042009-08-03 04:13:23 -030098 .priv = 0}
99};
100
101/*
102 * cam uses endpoint 0x03 to send commands, 0x84 for read commands,
103 * and 0x82 for bulk transfer.
104 */
105
106/* All commands are two bytes only */
Patrice Chotard8715b162011-04-18 17:38:37 -0300107static void jlj_write2(struct gspca_dev *gspca_dev, unsigned char *command)
Theodore Kilgore3040b042009-08-03 04:13:23 -0300108{
109 int retval;
110
Patrice Chotard8715b162011-04-18 17:38:37 -0300111 if (gspca_dev->usb_err < 0)
112 return;
Theodore Kilgore3040b042009-08-03 04:13:23 -0300113 memcpy(gspca_dev->usb_buf, command, 2);
114 retval = usb_bulk_msg(gspca_dev->dev,
115 usb_sndbulkpipe(gspca_dev->dev, 3),
116 gspca_dev->usb_buf, 2, NULL, 500);
Patrice Chotard8715b162011-04-18 17:38:37 -0300117 if (retval < 0) {
Joe Perches133a9fe2011-08-21 19:56:57 -0300118 pr_err("command write [%02x] error %d\n",
119 gspca_dev->usb_buf[0], retval);
Patrice Chotard8715b162011-04-18 17:38:37 -0300120 gspca_dev->usb_err = retval;
121 }
Theodore Kilgore3040b042009-08-03 04:13:23 -0300122}
123
124/* Responses are one byte only */
Patrice Chotard8715b162011-04-18 17:38:37 -0300125static void jlj_read1(struct gspca_dev *gspca_dev, unsigned char response)
Theodore Kilgore3040b042009-08-03 04:13:23 -0300126{
127 int retval;
128
Patrice Chotard8715b162011-04-18 17:38:37 -0300129 if (gspca_dev->usb_err < 0)
130 return;
Theodore Kilgore3040b042009-08-03 04:13:23 -0300131 retval = usb_bulk_msg(gspca_dev->dev,
132 usb_rcvbulkpipe(gspca_dev->dev, 0x84),
133 gspca_dev->usb_buf, 1, NULL, 500);
134 response = gspca_dev->usb_buf[0];
Patrice Chotard8715b162011-04-18 17:38:37 -0300135 if (retval < 0) {
Joe Perches133a9fe2011-08-21 19:56:57 -0300136 pr_err("read command [%02x] error %d\n",
137 gspca_dev->usb_buf[0], retval);
Patrice Chotard8715b162011-04-18 17:38:37 -0300138 gspca_dev->usb_err = retval;
139 }
Theodore Kilgore3040b042009-08-03 04:13:23 -0300140}
141
Patrice Chotard5396e622011-04-18 17:42:06 -0300142static void setfreq(struct gspca_dev *gspca_dev)
143{
144 struct sd *sd = (struct sd *) gspca_dev;
145 u8 freq_commands[][2] = {
146 {0x71, 0x80},
147 {0x70, 0x07}
148 };
149
150 freq_commands[0][1] |= (sd->ctrls[LIGHTFREQ].val >> 1);
151
152 jlj_write2(gspca_dev, freq_commands[0]);
153 jlj_write2(gspca_dev, freq_commands[1]);
154}
155
156static void setcamquality(struct gspca_dev *gspca_dev)
157{
158 struct sd *sd = (struct sd *) gspca_dev;
159 u8 quality_commands[][2] = {
160 {0x71, 0x1E},
161 {0x70, 0x06}
162 };
163 u8 camquality;
164
165 /* adapt camera quality from jpeg quality */
166 camquality = ((QUALITY_MAX - sd->quality) * CAMQUALITY_MAX)
167 / (QUALITY_MAX - QUALITY_MIN);
168 quality_commands[0][1] += camquality;
169
170 jlj_write2(gspca_dev, quality_commands[0]);
171 jlj_write2(gspca_dev, quality_commands[1]);
172}
173
174static void setautogain(struct gspca_dev *gspca_dev)
175{
176 struct sd *sd = (struct sd *) gspca_dev;
177 u8 autogain_commands[][2] = {
178 {0x94, 0x02},
179 {0xcf, 0x00}
180 };
181
182 autogain_commands[1][1] = (sd->ctrls[AUTOGAIN].val << 4);
183
184 jlj_write2(gspca_dev, autogain_commands[0]);
185 jlj_write2(gspca_dev, autogain_commands[1]);
186}
187
188static void setred(struct gspca_dev *gspca_dev)
189{
190 struct sd *sd = (struct sd *) gspca_dev;
191 u8 setred_commands[][2] = {
192 {0x94, 0x02},
193 {0xe6, 0x00}
194 };
195
196 setred_commands[1][1] = sd->ctrls[RED].val;
197
198 jlj_write2(gspca_dev, setred_commands[0]);
199 jlj_write2(gspca_dev, setred_commands[1]);
200}
201
202static void setgreen(struct gspca_dev *gspca_dev)
203{
204 struct sd *sd = (struct sd *) gspca_dev;
205 u8 setgreen_commands[][2] = {
206 {0x94, 0x02},
207 {0xe7, 0x00}
208 };
209
210 setgreen_commands[1][1] = sd->ctrls[GREEN].val;
211
212 jlj_write2(gspca_dev, setgreen_commands[0]);
213 jlj_write2(gspca_dev, setgreen_commands[1]);
214}
215
216static void setblue(struct gspca_dev *gspca_dev)
217{
218 struct sd *sd = (struct sd *) gspca_dev;
219 u8 setblue_commands[][2] = {
220 {0x94, 0x02},
221 {0xe9, 0x00}
222 };
223
224 setblue_commands[1][1] = sd->ctrls[BLUE].val;
225
226 jlj_write2(gspca_dev, setblue_commands[0]);
227 jlj_write2(gspca_dev, setblue_commands[1]);
228}
229
230static const struct ctrl sd_ctrls[NCTRLS] = {
231[LIGHTFREQ] = {
232 {
233 .id = V4L2_CID_POWER_LINE_FREQUENCY,
234 .type = V4L2_CTRL_TYPE_MENU,
235 .name = "Light frequency filter",
236 .minimum = V4L2_CID_POWER_LINE_FREQUENCY_DISABLED, /* 1 */
237 .maximum = V4L2_CID_POWER_LINE_FREQUENCY_60HZ, /* 2 */
238 .step = 1,
239 .default_value = V4L2_CID_POWER_LINE_FREQUENCY_60HZ,
240 },
241 .set_control = setfreq
242 },
243[AUTOGAIN] = {
244 {
245 .id = V4L2_CID_AUTOGAIN,
246 .type = V4L2_CTRL_TYPE_INTEGER,
247 .name = "Automatic Gain (and Exposure)",
248 .minimum = 0,
249 .maximum = 3,
250 .step = 1,
251#define AUTOGAIN_DEF 0
252 .default_value = AUTOGAIN_DEF,
253 },
254 .set_control = setautogain
255 },
256[RED] = {
257 {
258 .id = V4L2_CID_RED_BALANCE,
259 .type = V4L2_CTRL_TYPE_INTEGER,
260 .name = "red balance",
261 .minimum = 0,
262 .maximum = 3,
263 .step = 1,
264#define RED_BALANCE_DEF 2
265 .default_value = RED_BALANCE_DEF,
266 },
267 .set_control = setred
268 },
269
270[GREEN] = {
271 {
272 .id = V4L2_CID_GAIN,
273 .type = V4L2_CTRL_TYPE_INTEGER,
274 .name = "green balance",
275 .minimum = 0,
276 .maximum = 3,
277 .step = 1,
278#define GREEN_BALANCE_DEF 2
279 .default_value = GREEN_BALANCE_DEF,
280 },
281 .set_control = setgreen
282 },
283[BLUE] = {
284 {
285 .id = V4L2_CID_BLUE_BALANCE,
286 .type = V4L2_CTRL_TYPE_INTEGER,
287 .name = "blue balance",
288 .minimum = 0,
289 .maximum = 3,
290 .step = 1,
291#define BLUE_BALANCE_DEF 2
292 .default_value = BLUE_BALANCE_DEF,
293 },
294 .set_control = setblue
295 },
296};
297
Theodore Kilgore3040b042009-08-03 04:13:23 -0300298static int jlj_start(struct gspca_dev *gspca_dev)
299{
300 int i;
Patrice Chotard713b4662011-04-18 17:40:54 -0300301 int start_commands_size;
Theodore Kilgore3040b042009-08-03 04:13:23 -0300302 u8 response = 0xff;
Patrice Chotardc3d86922011-04-18 17:37:06 -0300303 struct sd *sd = (struct sd *) gspca_dev;
Theodore Kilgore3040b042009-08-03 04:13:23 -0300304 struct jlj_command start_commands[] = {
Patrice Chotard713b4662011-04-18 17:40:54 -0300305 {{0x71, 0x81}, 0, 0},
306 {{0x70, 0x05}, 0, JEILINJ_CMD_DELAY},
307 {{0x95, 0x70}, 1, 0},
308 {{0x71, 0x81 - gspca_dev->curr_mode}, 0, 0},
309 {{0x70, 0x04}, 0, JEILINJ_CMD_DELAY},
310 {{0x95, 0x70}, 1, 0},
311 {{0x71, 0x00}, 0, 0}, /* start streaming ??*/
312 {{0x70, 0x08}, 0, JEILINJ_CMD_DELAY},
313 {{0x95, 0x70}, 1, 0},
314#define SPORTSCAM_DV15_CMD_SIZE 9
315 {{0x94, 0x02}, 0, 0},
316 {{0xde, 0x24}, 0, 0},
317 {{0x94, 0x02}, 0, 0},
318 {{0xdd, 0xf0}, 0, 0},
319 {{0x94, 0x02}, 0, 0},
320 {{0xe3, 0x2c}, 0, 0},
321 {{0x94, 0x02}, 0, 0},
322 {{0xe4, 0x00}, 0, 0},
323 {{0x94, 0x02}, 0, 0},
324 {{0xe5, 0x00}, 0, 0},
325 {{0x94, 0x02}, 0, 0},
326 {{0xe6, 0x2c}, 0, 0},
327 {{0x94, 0x03}, 0, 0},
Patrice Chotard5396e622011-04-18 17:42:06 -0300328 {{0xaa, 0x00}, 0, 0}
Theodore Kilgore3040b042009-08-03 04:13:23 -0300329 };
Patrice Chotardc3d86922011-04-18 17:37:06 -0300330
331 sd->blocks_left = 0;
Patrice Chotard713b4662011-04-18 17:40:54 -0300332 /* Under Windows, USB spy shows that only the 9 first start
333 * commands are used for SPORTSCAM_DV15 webcam
334 */
335 if (sd->type == SPORTSCAM_DV15)
336 start_commands_size = SPORTSCAM_DV15_CMD_SIZE;
337 else
338 start_commands_size = ARRAY_SIZE(start_commands);
339
340 for (i = 0; i < start_commands_size; i++) {
Patrice Chotard8715b162011-04-18 17:38:37 -0300341 jlj_write2(gspca_dev, start_commands[i].instruction);
Patrice Chotard713b4662011-04-18 17:40:54 -0300342 if (start_commands[i].delay)
343 msleep(start_commands[i].delay);
Theodore Kilgore3040b042009-08-03 04:13:23 -0300344 if (start_commands[i].ack_wanted)
Patrice Chotard8715b162011-04-18 17:38:37 -0300345 jlj_read1(gspca_dev, response);
Theodore Kilgore3040b042009-08-03 04:13:23 -0300346 }
Patrice Chotard5396e622011-04-18 17:42:06 -0300347 setcamquality(gspca_dev);
348 msleep(2);
349 setfreq(gspca_dev);
Patrice Chotard8715b162011-04-18 17:38:37 -0300350 if (gspca_dev->usb_err < 0)
351 PDEBUG(D_ERR, "Start streaming command failed");
352 return gspca_dev->usb_err;
Theodore Kilgore3040b042009-08-03 04:13:23 -0300353}
354
Patrice Chotardc3d86922011-04-18 17:37:06 -0300355static void sd_pkt_scan(struct gspca_dev *gspca_dev,
356 u8 *data, int len)
Theodore Kilgore3040b042009-08-03 04:13:23 -0300357{
Patrice Chotardc3d86922011-04-18 17:37:06 -0300358 struct sd *sd = (struct sd *) gspca_dev;
Theodore Kilgore3040b042009-08-03 04:13:23 -0300359 int packet_type;
Patrice Chotardc3d86922011-04-18 17:37:06 -0300360 u32 header_marker;
Theodore Kilgore3040b042009-08-03 04:13:23 -0300361
Patrice Chotardc3d86922011-04-18 17:37:06 -0300362 PDEBUG(D_STREAM, "Got %d bytes out of %d for Block 0",
363 len, JEILINJ_MAX_TRANSFER);
364 if (len != JEILINJ_MAX_TRANSFER) {
365 PDEBUG(D_PACK, "bad length");
366 goto discard;
Theodore Kilgore3040b042009-08-03 04:13:23 -0300367 }
Patrice Chotardc3d86922011-04-18 17:37:06 -0300368 /* check if it's start of frame */
369 header_marker = ((u32 *)data)[0];
370 if (header_marker == FRAME_START) {
371 sd->blocks_left = data[0x0a] - 1;
372 PDEBUG(D_STREAM, "blocks_left = 0x%x", sd->blocks_left);
Hans de Goede6ca3f252009-10-09 03:58:35 -0300373 /* Start a new frame, and add the JPEG header, first thing */
Jean-Francois Moine76dd2722009-11-13 09:21:03 -0300374 gspca_frame_add(gspca_dev, FIRST_PACKET,
Patrice Chotardc3d86922011-04-18 17:37:06 -0300375 sd->jpeg_hdr, JPEG_HDR_SZ);
Jean-Francois Moine76dd2722009-11-13 09:21:03 -0300376 /* Toss line 0 of data block 0, keep the rest. */
377 gspca_frame_add(gspca_dev, INTER_PACKET,
Patrice Chotardc3d86922011-04-18 17:37:06 -0300378 data + FRAME_HEADER_LEN,
Theodore Kilgore3040b042009-08-03 04:13:23 -0300379 JEILINJ_MAX_TRANSFER - FRAME_HEADER_LEN);
Patrice Chotardc3d86922011-04-18 17:37:06 -0300380 } else if (sd->blocks_left > 0) {
381 PDEBUG(D_STREAM, "%d blocks remaining for frame",
382 sd->blocks_left);
383 sd->blocks_left -= 1;
384 if (sd->blocks_left == 0)
385 packet_type = LAST_PACKET;
386 else
387 packet_type = INTER_PACKET;
388 gspca_frame_add(gspca_dev, packet_type,
389 data, JEILINJ_MAX_TRANSFER);
390 } else
391 goto discard;
392 return;
393discard:
394 /* Discard data until a new frame starts. */
395 gspca_dev->last_packet_type = DISCARD_PACKET;
Theodore Kilgore3040b042009-08-03 04:13:23 -0300396}
397
398/* This function is called at probe time just before sd_init */
399static int sd_config(struct gspca_dev *gspca_dev,
400 const struct usb_device_id *id)
401{
402 struct cam *cam = &gspca_dev->cam;
403 struct sd *dev = (struct sd *) gspca_dev;
404
Patrice Chotard713b4662011-04-18 17:40:54 -0300405 dev->type = id->driver_info;
Patrice Chotard5396e622011-04-18 17:42:06 -0300406 gspca_dev->cam.ctrls = dev->ctrls;
407 dev->quality = QUALITY_DEF;
Jean-François Moine7d84a172011-07-03 07:27:24 -0300408
Theodore Kilgore3040b042009-08-03 04:13:23 -0300409 cam->cam_mode = jlj_mode;
Patrice Chotard6f8efcf2011-04-18 17:39:38 -0300410 cam->nmodes = ARRAY_SIZE(jlj_mode);
Theodore Kilgore3040b042009-08-03 04:13:23 -0300411 cam->bulk = 1;
Patrice Chotardc3d86922011-04-18 17:37:06 -0300412 cam->bulk_nurbs = 1;
413 cam->bulk_size = JEILINJ_MAX_TRANSFER;
Theodore Kilgore3040b042009-08-03 04:13:23 -0300414 return 0;
415}
416
Patrice Chotardc3d86922011-04-18 17:37:06 -0300417static void sd_stopN(struct gspca_dev *gspca_dev)
Theodore Kilgore3040b042009-08-03 04:13:23 -0300418{
Patrice Chotardc3d86922011-04-18 17:37:06 -0300419 int i;
420 u8 *buf;
Jean-François Moine7d84a172011-07-03 07:27:24 -0300421 static u8 stop_commands[][2] = {
Patrice Chotardc3d86922011-04-18 17:37:06 -0300422 {0x71, 0x00},
423 {0x70, 0x09},
424 {0x71, 0x80},
425 {0x70, 0x05}
426 };
Theodore Kilgore3040b042009-08-03 04:13:23 -0300427
Patrice Chotardc3d86922011-04-18 17:37:06 -0300428 for (;;) {
429 /* get the image remaining blocks */
430 usb_bulk_msg(gspca_dev->dev,
431 gspca_dev->urb[0]->pipe,
432 gspca_dev->urb[0]->transfer_buffer,
433 JEILINJ_MAX_TRANSFER, NULL,
434 JEILINJ_DATA_TIMEOUT);
435
436 /* search for 0xff 0xd9 (EOF for JPEG) */
437 i = 0;
438 buf = gspca_dev->urb[0]->transfer_buffer;
439 while ((i < (JEILINJ_MAX_TRANSFER - 1)) &&
440 ((buf[i] != 0xff) || (buf[i+1] != 0xd9)))
441 i++;
442
443 if (i != (JEILINJ_MAX_TRANSFER - 1))
444 /* last remaining block found */
445 break;
446 }
447
448 for (i = 0; i < ARRAY_SIZE(stop_commands); i++)
449 jlj_write2(gspca_dev, stop_commands[i]);
Theodore Kilgore3040b042009-08-03 04:13:23 -0300450}
451
452/* this function is called at probe and resume time */
453static int sd_init(struct gspca_dev *gspca_dev)
454{
Patrice Chotard8715b162011-04-18 17:38:37 -0300455 return gspca_dev->usb_err;
Theodore Kilgore3040b042009-08-03 04:13:23 -0300456}
457
458/* Set up for getting frames. */
459static int sd_start(struct gspca_dev *gspca_dev)
460{
461 struct sd *dev = (struct sd *) gspca_dev;
Theodore Kilgore3040b042009-08-03 04:13:23 -0300462
463 /* create the JPEG header */
Theodore Kilgore3040b042009-08-03 04:13:23 -0300464 jpeg_define(dev->jpeg_hdr, gspca_dev->height, gspca_dev->width,
465 0x21); /* JPEG 422 */
466 jpeg_set_qual(dev->jpeg_hdr, dev->quality);
Patrice Chotard6f8efcf2011-04-18 17:39:38 -0300467 PDEBUG(D_STREAM, "Start streaming at %dx%d",
468 gspca_dev->height, gspca_dev->width);
Patrice Chotard8715b162011-04-18 17:38:37 -0300469 jlj_start(gspca_dev);
470 return gspca_dev->usb_err;
Theodore Kilgore3040b042009-08-03 04:13:23 -0300471}
472
473/* Table of supported USB devices */
Jean-François Moine95c967c2011-01-13 05:20:29 -0300474static const struct usb_device_id device_table[] = {
Patrice Chotard713b4662011-04-18 17:40:54 -0300475 {USB_DEVICE(0x0979, 0x0280), .driver_info = SAKAR_57379},
476 {USB_DEVICE(0x0979, 0x0270), .driver_info = SPORTSCAM_DV15},
Theodore Kilgore3040b042009-08-03 04:13:23 -0300477 {}
478};
479
480MODULE_DEVICE_TABLE(usb, device_table);
481
Patrice Chotard5396e622011-04-18 17:42:06 -0300482static int sd_querymenu(struct gspca_dev *gspca_dev,
483 struct v4l2_querymenu *menu)
484{
485 switch (menu->id) {
486 case V4L2_CID_POWER_LINE_FREQUENCY:
487 switch (menu->index) {
488 case 0: /* V4L2_CID_POWER_LINE_FREQUENCY_DISABLED */
489 strcpy((char *) menu->name, "disable");
490 return 0;
491 case 1: /* V4L2_CID_POWER_LINE_FREQUENCY_50HZ */
492 strcpy((char *) menu->name, "50 Hz");
493 return 0;
494 case 2: /* V4L2_CID_POWER_LINE_FREQUENCY_60HZ */
495 strcpy((char *) menu->name, "60 Hz");
496 return 0;
497 }
498 break;
499 }
500 return -EINVAL;
501}
502
503static int sd_set_jcomp(struct gspca_dev *gspca_dev,
504 struct v4l2_jpegcompression *jcomp)
505{
506 struct sd *sd = (struct sd *) gspca_dev;
507
508 if (jcomp->quality < QUALITY_MIN)
509 sd->quality = QUALITY_MIN;
510 else if (jcomp->quality > QUALITY_MAX)
511 sd->quality = QUALITY_MAX;
512 else
513 sd->quality = jcomp->quality;
514 if (gspca_dev->streaming) {
515 jpeg_set_qual(sd->jpeg_hdr, sd->quality);
516 setcamquality(gspca_dev);
517 }
518 return 0;
519}
520
521static int sd_get_jcomp(struct gspca_dev *gspca_dev,
522 struct v4l2_jpegcompression *jcomp)
523{
524 struct sd *sd = (struct sd *) gspca_dev;
525
526 memset(jcomp, 0, sizeof *jcomp);
527 jcomp->quality = sd->quality;
528 jcomp->jpeg_markers = V4L2_JPEG_MARKER_DHT
529 | V4L2_JPEG_MARKER_DQT;
530 return 0;
531}
532
533
Theodore Kilgore3040b042009-08-03 04:13:23 -0300534/* sub-driver description */
Patrice Chotard713b4662011-04-18 17:40:54 -0300535static const struct sd_desc sd_desc_sakar_57379 = {
Theodore Kilgore3040b042009-08-03 04:13:23 -0300536 .name = MODULE_NAME,
537 .config = sd_config,
538 .init = sd_init,
539 .start = sd_start,
Patrice Chotardc3d86922011-04-18 17:37:06 -0300540 .stopN = sd_stopN,
541 .pkt_scan = sd_pkt_scan,
Theodore Kilgore3040b042009-08-03 04:13:23 -0300542};
543
Patrice Chotard713b4662011-04-18 17:40:54 -0300544/* sub-driver description */
545static const struct sd_desc sd_desc_sportscam_dv15 = {
546 .name = MODULE_NAME,
547 .config = sd_config,
548 .init = sd_init,
549 .start = sd_start,
550 .stopN = sd_stopN,
551 .pkt_scan = sd_pkt_scan,
Patrice Chotard5396e622011-04-18 17:42:06 -0300552 .ctrls = sd_ctrls,
553 .nctrls = ARRAY_SIZE(sd_ctrls),
554 .querymenu = sd_querymenu,
555 .get_jcomp = sd_get_jcomp,
556 .set_jcomp = sd_set_jcomp,
Patrice Chotard713b4662011-04-18 17:40:54 -0300557};
558
559static const struct sd_desc *sd_desc[2] = {
560 &sd_desc_sakar_57379,
561 &sd_desc_sportscam_dv15
562};
563
Theodore Kilgore3040b042009-08-03 04:13:23 -0300564/* -- device connect -- */
565static int sd_probe(struct usb_interface *intf,
566 const struct usb_device_id *id)
567{
568 return gspca_dev_probe(intf, id,
Patrice Chotard713b4662011-04-18 17:40:54 -0300569 sd_desc[id->driver_info],
Theodore Kilgore3040b042009-08-03 04:13:23 -0300570 sizeof(struct sd),
571 THIS_MODULE);
572}
573
574static struct usb_driver sd_driver = {
575 .name = MODULE_NAME,
576 .id_table = device_table,
577 .probe = sd_probe,
578 .disconnect = gspca_disconnect,
579#ifdef CONFIG_PM
580 .suspend = gspca_suspend,
581 .resume = gspca_resume,
582#endif
583};
584
Greg Kroah-Hartmanecb3b2b2011-11-18 09:46:12 -0800585module_usb_driver(sd_driver);