diff options
Diffstat (limited to 'drivers/media/video/gspca/jeilinj.c')
-rw-r--r-- | drivers/media/video/gspca/jeilinj.c | 581 |
1 files changed, 409 insertions, 172 deletions
diff --git a/drivers/media/video/gspca/jeilinj.c b/drivers/media/video/gspca/jeilinj.c index 36dae38b1e38..1bd9c4b542dd 100644 --- a/drivers/media/video/gspca/jeilinj.c +++ b/drivers/media/video/gspca/jeilinj.c | |||
@@ -6,6 +6,9 @@ | |||
6 | * | 6 | * |
7 | * Copyright (C) 2009 Theodore Kilgore | 7 | * Copyright (C) 2009 Theodore Kilgore |
8 | * | 8 | * |
9 | * Sportscam DV15 support and control settings are | ||
10 | * Copyright (C) 2011 Patrice Chotard | ||
11 | * | ||
9 | * This program is free software; you can redistribute it and/or modify | 12 | * This program is free software; you can redistribute it and/or modify |
10 | * it under the terms of the GNU General Public License as published by | 13 | * it under the terms of the GNU General Public License as published by |
11 | * the Free Software Foundation; either version 2 of the License, or | 14 | * the Free Software Foundation; either version 2 of the License, or |
@@ -23,7 +26,6 @@ | |||
23 | 26 | ||
24 | #define MODULE_NAME "jeilinj" | 27 | #define MODULE_NAME "jeilinj" |
25 | 28 | ||
26 | #include <linux/workqueue.h> | ||
27 | #include <linux/slab.h> | 29 | #include <linux/slab.h> |
28 | #include "gspca.h" | 30 | #include "gspca.h" |
29 | #include "jpeg.h" | 31 | #include "jpeg.h" |
@@ -34,29 +36,51 @@ MODULE_LICENSE("GPL"); | |||
34 | 36 | ||
35 | /* Default timeouts, in ms */ | 37 | /* Default timeouts, in ms */ |
36 | #define JEILINJ_CMD_TIMEOUT 500 | 38 | #define JEILINJ_CMD_TIMEOUT 500 |
39 | #define JEILINJ_CMD_DELAY 160 | ||
37 | #define JEILINJ_DATA_TIMEOUT 1000 | 40 | #define JEILINJ_DATA_TIMEOUT 1000 |
38 | 41 | ||
39 | /* Maximum transfer size to use. */ | 42 | /* Maximum transfer size to use. */ |
40 | #define JEILINJ_MAX_TRANSFER 0x200 | 43 | #define JEILINJ_MAX_TRANSFER 0x200 |
41 | |||
42 | #define FRAME_HEADER_LEN 0x10 | 44 | #define FRAME_HEADER_LEN 0x10 |
45 | #define FRAME_START 0xFFFFFFFF | ||
46 | |||
47 | enum { | ||
48 | SAKAR_57379, | ||
49 | SPORTSCAM_DV15, | ||
50 | }; | ||
51 | |||
52 | #define CAMQUALITY_MIN 0 /* highest cam quality */ | ||
53 | #define CAMQUALITY_MAX 97 /* lowest cam quality */ | ||
54 | |||
55 | enum e_ctrl { | ||
56 | LIGHTFREQ, | ||
57 | AUTOGAIN, | ||
58 | RED, | ||
59 | GREEN, | ||
60 | BLUE, | ||
61 | NCTRLS /* number of controls */ | ||
62 | }; | ||
43 | 63 | ||
44 | /* Structure to hold all of our device specific stuff */ | 64 | /* Structure to hold all of our device specific stuff */ |
45 | struct sd { | 65 | struct sd { |
46 | struct gspca_dev gspca_dev; /* !! must be the first item */ | 66 | struct gspca_dev gspca_dev; /* !! must be the first item */ |
67 | struct gspca_ctrl ctrls[NCTRLS]; | ||
68 | int blocks_left; | ||
47 | const struct v4l2_pix_format *cap_mode; | 69 | const struct v4l2_pix_format *cap_mode; |
48 | /* Driver stuff */ | 70 | /* Driver stuff */ |
49 | struct work_struct work_struct; | 71 | u8 type; |
50 | struct workqueue_struct *work_thread; | ||
51 | u8 quality; /* image quality */ | 72 | u8 quality; /* image quality */ |
52 | u8 jpegqual; /* webcam quality */ | 73 | #define QUALITY_MIN 35 |
74 | #define QUALITY_MAX 85 | ||
75 | #define QUALITY_DEF 85 | ||
53 | u8 jpeg_hdr[JPEG_HDR_SZ]; | 76 | u8 jpeg_hdr[JPEG_HDR_SZ]; |
54 | }; | 77 | }; |
55 | 78 | ||
56 | struct jlj_command { | 79 | struct jlj_command { |
57 | unsigned char instruction[2]; | 80 | unsigned char instruction[2]; |
58 | unsigned char ack_wanted; | 81 | unsigned char ack_wanted; |
59 | }; | 82 | unsigned char delay; |
83 | }; | ||
60 | 84 | ||
61 | /* AFAICT these cameras will only do 320x240. */ | 85 | /* AFAICT these cameras will only do 320x240. */ |
62 | static struct v4l2_pix_format jlj_mode[] = { | 86 | static struct v4l2_pix_format jlj_mode[] = { |
@@ -64,6 +88,11 @@ static struct v4l2_pix_format jlj_mode[] = { | |||
64 | .bytesperline = 320, | 88 | .bytesperline = 320, |
65 | .sizeimage = 320 * 240, | 89 | .sizeimage = 320 * 240, |
66 | .colorspace = V4L2_COLORSPACE_JPEG, | 90 | .colorspace = V4L2_COLORSPACE_JPEG, |
91 | .priv = 0}, | ||
92 | { 640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, | ||
93 | .bytesperline = 640, | ||
94 | .sizeimage = 640 * 480, | ||
95 | .colorspace = V4L2_COLORSPACE_JPEG, | ||
67 | .priv = 0} | 96 | .priv = 0} |
68 | }; | 97 | }; |
69 | 98 | ||
@@ -73,178 +102,295 @@ static struct v4l2_pix_format jlj_mode[] = { | |||
73 | */ | 102 | */ |
74 | 103 | ||
75 | /* All commands are two bytes only */ | 104 | /* All commands are two bytes only */ |
76 | static int jlj_write2(struct gspca_dev *gspca_dev, unsigned char *command) | 105 | static void jlj_write2(struct gspca_dev *gspca_dev, unsigned char *command) |
77 | { | 106 | { |
78 | int retval; | 107 | int retval; |
79 | 108 | ||
109 | if (gspca_dev->usb_err < 0) | ||
110 | return; | ||
80 | memcpy(gspca_dev->usb_buf, command, 2); | 111 | memcpy(gspca_dev->usb_buf, command, 2); |
81 | retval = usb_bulk_msg(gspca_dev->dev, | 112 | retval = usb_bulk_msg(gspca_dev->dev, |
82 | usb_sndbulkpipe(gspca_dev->dev, 3), | 113 | usb_sndbulkpipe(gspca_dev->dev, 3), |
83 | gspca_dev->usb_buf, 2, NULL, 500); | 114 | gspca_dev->usb_buf, 2, NULL, 500); |
84 | if (retval < 0) | 115 | if (retval < 0) { |
85 | err("command write [%02x] error %d", | 116 | err("command write [%02x] error %d", |
86 | gspca_dev->usb_buf[0], retval); | 117 | gspca_dev->usb_buf[0], retval); |
87 | return retval; | 118 | gspca_dev->usb_err = retval; |
119 | } | ||
88 | } | 120 | } |
89 | 121 | ||
90 | /* Responses are one byte only */ | 122 | /* Responses are one byte only */ |
91 | static int jlj_read1(struct gspca_dev *gspca_dev, unsigned char response) | 123 | static void jlj_read1(struct gspca_dev *gspca_dev, unsigned char response) |
92 | { | 124 | { |
93 | int retval; | 125 | int retval; |
94 | 126 | ||
127 | if (gspca_dev->usb_err < 0) | ||
128 | return; | ||
95 | retval = usb_bulk_msg(gspca_dev->dev, | 129 | retval = usb_bulk_msg(gspca_dev->dev, |
96 | usb_rcvbulkpipe(gspca_dev->dev, 0x84), | 130 | usb_rcvbulkpipe(gspca_dev->dev, 0x84), |
97 | gspca_dev->usb_buf, 1, NULL, 500); | 131 | gspca_dev->usb_buf, 1, NULL, 500); |
98 | response = gspca_dev->usb_buf[0]; | 132 | response = gspca_dev->usb_buf[0]; |
99 | if (retval < 0) | 133 | if (retval < 0) { |
100 | err("read command [%02x] error %d", | 134 | err("read command [%02x] error %d", |
101 | gspca_dev->usb_buf[0], retval); | 135 | gspca_dev->usb_buf[0], retval); |
102 | return retval; | 136 | gspca_dev->usb_err = retval; |
137 | } | ||
103 | } | 138 | } |
104 | 139 | ||
105 | static int jlj_start(struct gspca_dev *gspca_dev) | 140 | static void setfreq(struct gspca_dev *gspca_dev) |
106 | { | 141 | { |
107 | int i; | 142 | struct sd *sd = (struct sd *) gspca_dev; |
108 | int retval = -1; | 143 | u8 freq_commands[][2] = { |
109 | u8 response = 0xff; | 144 | {0x71, 0x80}, |
110 | struct jlj_command start_commands[] = { | 145 | {0x70, 0x07} |
111 | {{0x71, 0x81}, 0}, | ||
112 | {{0x70, 0x05}, 0}, | ||
113 | {{0x95, 0x70}, 1}, | ||
114 | {{0x71, 0x81}, 0}, | ||
115 | {{0x70, 0x04}, 0}, | ||
116 | {{0x95, 0x70}, 1}, | ||
117 | {{0x71, 0x00}, 0}, | ||
118 | {{0x70, 0x08}, 0}, | ||
119 | {{0x95, 0x70}, 1}, | ||
120 | {{0x94, 0x02}, 0}, | ||
121 | {{0xde, 0x24}, 0}, | ||
122 | {{0x94, 0x02}, 0}, | ||
123 | {{0xdd, 0xf0}, 0}, | ||
124 | {{0x94, 0x02}, 0}, | ||
125 | {{0xe3, 0x2c}, 0}, | ||
126 | {{0x94, 0x02}, 0}, | ||
127 | {{0xe4, 0x00}, 0}, | ||
128 | {{0x94, 0x02}, 0}, | ||
129 | {{0xe5, 0x00}, 0}, | ||
130 | {{0x94, 0x02}, 0}, | ||
131 | {{0xe6, 0x2c}, 0}, | ||
132 | {{0x94, 0x03}, 0}, | ||
133 | {{0xaa, 0x00}, 0}, | ||
134 | {{0x71, 0x1e}, 0}, | ||
135 | {{0x70, 0x06}, 0}, | ||
136 | {{0x71, 0x80}, 0}, | ||
137 | {{0x70, 0x07}, 0} | ||
138 | }; | 146 | }; |
139 | for (i = 0; i < ARRAY_SIZE(start_commands); i++) { | 147 | |
140 | retval = jlj_write2(gspca_dev, start_commands[i].instruction); | 148 | freq_commands[0][1] |= (sd->ctrls[LIGHTFREQ].val >> 1); |
141 | if (retval < 0) | 149 | |
142 | return retval; | 150 | jlj_write2(gspca_dev, freq_commands[0]); |
143 | if (start_commands[i].ack_wanted) | 151 | jlj_write2(gspca_dev, freq_commands[1]); |
144 | retval = jlj_read1(gspca_dev, response); | ||
145 | if (retval < 0) | ||
146 | return retval; | ||
147 | } | ||
148 | PDEBUG(D_ERR, "jlj_start retval is %d", retval); | ||
149 | return retval; | ||
150 | } | 152 | } |
151 | 153 | ||
152 | static int jlj_stop(struct gspca_dev *gspca_dev) | 154 | static void setcamquality(struct gspca_dev *gspca_dev) |
155 | { | ||
156 | struct sd *sd = (struct sd *) gspca_dev; | ||
157 | u8 quality_commands[][2] = { | ||
158 | {0x71, 0x1E}, | ||
159 | {0x70, 0x06} | ||
160 | }; | ||
161 | u8 camquality; | ||
162 | |||
163 | /* adapt camera quality from jpeg quality */ | ||
164 | camquality = ((QUALITY_MAX - sd->quality) * CAMQUALITY_MAX) | ||
165 | / (QUALITY_MAX - QUALITY_MIN); | ||
166 | quality_commands[0][1] += camquality; | ||
167 | |||
168 | jlj_write2(gspca_dev, quality_commands[0]); | ||
169 | jlj_write2(gspca_dev, quality_commands[1]); | ||
170 | } | ||
171 | |||
172 | static void setautogain(struct gspca_dev *gspca_dev) | ||
173 | { | ||
174 | struct sd *sd = (struct sd *) gspca_dev; | ||
175 | u8 autogain_commands[][2] = { | ||
176 | {0x94, 0x02}, | ||
177 | {0xcf, 0x00} | ||
178 | }; | ||
179 | |||
180 | autogain_commands[1][1] = (sd->ctrls[AUTOGAIN].val << 4); | ||
181 | |||
182 | jlj_write2(gspca_dev, autogain_commands[0]); | ||
183 | jlj_write2(gspca_dev, autogain_commands[1]); | ||
184 | } | ||
185 | |||
186 | static void setred(struct gspca_dev *gspca_dev) | ||
187 | { | ||
188 | struct sd *sd = (struct sd *) gspca_dev; | ||
189 | u8 setred_commands[][2] = { | ||
190 | {0x94, 0x02}, | ||
191 | {0xe6, 0x00} | ||
192 | }; | ||
193 | |||
194 | setred_commands[1][1] = sd->ctrls[RED].val; | ||
195 | |||
196 | jlj_write2(gspca_dev, setred_commands[0]); | ||
197 | jlj_write2(gspca_dev, setred_commands[1]); | ||
198 | } | ||
199 | |||
200 | static void setgreen(struct gspca_dev *gspca_dev) | ||
201 | { | ||
202 | struct sd *sd = (struct sd *) gspca_dev; | ||
203 | u8 setgreen_commands[][2] = { | ||
204 | {0x94, 0x02}, | ||
205 | {0xe7, 0x00} | ||
206 | }; | ||
207 | |||
208 | setgreen_commands[1][1] = sd->ctrls[GREEN].val; | ||
209 | |||
210 | jlj_write2(gspca_dev, setgreen_commands[0]); | ||
211 | jlj_write2(gspca_dev, setgreen_commands[1]); | ||
212 | } | ||
213 | |||
214 | static void setblue(struct gspca_dev *gspca_dev) | ||
215 | { | ||
216 | struct sd *sd = (struct sd *) gspca_dev; | ||
217 | u8 setblue_commands[][2] = { | ||
218 | {0x94, 0x02}, | ||
219 | {0xe9, 0x00} | ||
220 | }; | ||
221 | |||
222 | setblue_commands[1][1] = sd->ctrls[BLUE].val; | ||
223 | |||
224 | jlj_write2(gspca_dev, setblue_commands[0]); | ||
225 | jlj_write2(gspca_dev, setblue_commands[1]); | ||
226 | } | ||
227 | |||
228 | static const struct ctrl sd_ctrls[NCTRLS] = { | ||
229 | [LIGHTFREQ] = { | ||
230 | { | ||
231 | .id = V4L2_CID_POWER_LINE_FREQUENCY, | ||
232 | .type = V4L2_CTRL_TYPE_MENU, | ||
233 | .name = "Light frequency filter", | ||
234 | .minimum = V4L2_CID_POWER_LINE_FREQUENCY_DISABLED, /* 1 */ | ||
235 | .maximum = V4L2_CID_POWER_LINE_FREQUENCY_60HZ, /* 2 */ | ||
236 | .step = 1, | ||
237 | .default_value = V4L2_CID_POWER_LINE_FREQUENCY_60HZ, | ||
238 | }, | ||
239 | .set_control = setfreq | ||
240 | }, | ||
241 | [AUTOGAIN] = { | ||
242 | { | ||
243 | .id = V4L2_CID_AUTOGAIN, | ||
244 | .type = V4L2_CTRL_TYPE_INTEGER, | ||
245 | .name = "Automatic Gain (and Exposure)", | ||
246 | .minimum = 0, | ||
247 | .maximum = 3, | ||
248 | .step = 1, | ||
249 | #define AUTOGAIN_DEF 0 | ||
250 | .default_value = AUTOGAIN_DEF, | ||
251 | }, | ||
252 | .set_control = setautogain | ||
253 | }, | ||
254 | [RED] = { | ||
255 | { | ||
256 | .id = V4L2_CID_RED_BALANCE, | ||
257 | .type = V4L2_CTRL_TYPE_INTEGER, | ||
258 | .name = "red balance", | ||
259 | .minimum = 0, | ||
260 | .maximum = 3, | ||
261 | .step = 1, | ||
262 | #define RED_BALANCE_DEF 2 | ||
263 | .default_value = RED_BALANCE_DEF, | ||
264 | }, | ||
265 | .set_control = setred | ||
266 | }, | ||
267 | |||
268 | [GREEN] = { | ||
269 | { | ||
270 | .id = V4L2_CID_GAIN, | ||
271 | .type = V4L2_CTRL_TYPE_INTEGER, | ||
272 | .name = "green balance", | ||
273 | .minimum = 0, | ||
274 | .maximum = 3, | ||
275 | .step = 1, | ||
276 | #define GREEN_BALANCE_DEF 2 | ||
277 | .default_value = GREEN_BALANCE_DEF, | ||
278 | }, | ||
279 | .set_control = setgreen | ||
280 | }, | ||
281 | [BLUE] = { | ||
282 | { | ||
283 | .id = V4L2_CID_BLUE_BALANCE, | ||
284 | .type = V4L2_CTRL_TYPE_INTEGER, | ||
285 | .name = "blue balance", | ||
286 | .minimum = 0, | ||
287 | .maximum = 3, | ||
288 | .step = 1, | ||
289 | #define BLUE_BALANCE_DEF 2 | ||
290 | .default_value = BLUE_BALANCE_DEF, | ||
291 | }, | ||
292 | .set_control = setblue | ||
293 | }, | ||
294 | }; | ||
295 | |||
296 | static int jlj_start(struct gspca_dev *gspca_dev) | ||
153 | { | 297 | { |
154 | int i; | 298 | int i; |
155 | int retval; | 299 | int start_commands_size; |
156 | struct jlj_command stop_commands[] = { | 300 | u8 response = 0xff; |
157 | {{0x71, 0x00}, 0}, | 301 | struct sd *sd = (struct sd *) gspca_dev; |
158 | {{0x70, 0x09}, 0}, | 302 | struct jlj_command start_commands[] = { |
159 | {{0x71, 0x80}, 0}, | 303 | {{0x71, 0x81}, 0, 0}, |
160 | {{0x70, 0x05}, 0} | 304 | {{0x70, 0x05}, 0, JEILINJ_CMD_DELAY}, |
305 | {{0x95, 0x70}, 1, 0}, | ||
306 | {{0x71, 0x81 - gspca_dev->curr_mode}, 0, 0}, | ||
307 | {{0x70, 0x04}, 0, JEILINJ_CMD_DELAY}, | ||
308 | {{0x95, 0x70}, 1, 0}, | ||
309 | {{0x71, 0x00}, 0, 0}, /* start streaming ??*/ | ||
310 | {{0x70, 0x08}, 0, JEILINJ_CMD_DELAY}, | ||
311 | {{0x95, 0x70}, 1, 0}, | ||
312 | #define SPORTSCAM_DV15_CMD_SIZE 9 | ||
313 | {{0x94, 0x02}, 0, 0}, | ||
314 | {{0xde, 0x24}, 0, 0}, | ||
315 | {{0x94, 0x02}, 0, 0}, | ||
316 | {{0xdd, 0xf0}, 0, 0}, | ||
317 | {{0x94, 0x02}, 0, 0}, | ||
318 | {{0xe3, 0x2c}, 0, 0}, | ||
319 | {{0x94, 0x02}, 0, 0}, | ||
320 | {{0xe4, 0x00}, 0, 0}, | ||
321 | {{0x94, 0x02}, 0, 0}, | ||
322 | {{0xe5, 0x00}, 0, 0}, | ||
323 | {{0x94, 0x02}, 0, 0}, | ||
324 | {{0xe6, 0x2c}, 0, 0}, | ||
325 | {{0x94, 0x03}, 0, 0}, | ||
326 | {{0xaa, 0x00}, 0, 0} | ||
161 | }; | 327 | }; |
162 | for (i = 0; i < ARRAY_SIZE(stop_commands); i++) { | 328 | |
163 | retval = jlj_write2(gspca_dev, stop_commands[i].instruction); | 329 | sd->blocks_left = 0; |
164 | if (retval < 0) | 330 | /* Under Windows, USB spy shows that only the 9 first start |
165 | return retval; | 331 | * commands are used for SPORTSCAM_DV15 webcam |
332 | */ | ||
333 | if (sd->type == SPORTSCAM_DV15) | ||
334 | start_commands_size = SPORTSCAM_DV15_CMD_SIZE; | ||
335 | else | ||
336 | start_commands_size = ARRAY_SIZE(start_commands); | ||
337 | |||
338 | for (i = 0; i < start_commands_size; i++) { | ||
339 | jlj_write2(gspca_dev, start_commands[i].instruction); | ||
340 | if (start_commands[i].delay) | ||
341 | msleep(start_commands[i].delay); | ||
342 | if (start_commands[i].ack_wanted) | ||
343 | jlj_read1(gspca_dev, response); | ||
166 | } | 344 | } |
167 | return retval; | 345 | setcamquality(gspca_dev); |
346 | msleep(2); | ||
347 | setfreq(gspca_dev); | ||
348 | if (gspca_dev->usb_err < 0) | ||
349 | PDEBUG(D_ERR, "Start streaming command failed"); | ||
350 | return gspca_dev->usb_err; | ||
168 | } | 351 | } |
169 | 352 | ||
170 | /* This function is called as a workqueue function and runs whenever the camera | 353 | static void sd_pkt_scan(struct gspca_dev *gspca_dev, |
171 | * is streaming data. Because it is a workqueue function it is allowed to sleep | 354 | u8 *data, int len) |
172 | * so we can use synchronous USB calls. To avoid possible collisions with other | ||
173 | * threads attempting to use the camera's USB interface the gspca usb_lock is | ||
174 | * used when performing the one USB control operation inside the workqueue, | ||
175 | * which tells the camera to close the stream. In practice the only thing | ||
176 | * which needs to be protected against is the usb_set_interface call that | ||
177 | * gspca makes during stream_off. Otherwise the camera doesn't provide any | ||
178 | * controls that the user could try to change. | ||
179 | */ | ||
180 | |||
181 | static void jlj_dostream(struct work_struct *work) | ||
182 | { | 355 | { |
183 | struct sd *dev = container_of(work, struct sd, work_struct); | 356 | struct sd *sd = (struct sd *) gspca_dev; |
184 | struct gspca_dev *gspca_dev = &dev->gspca_dev; | ||
185 | int blocks_left; /* 0x200-sized blocks remaining in current frame. */ | ||
186 | int act_len; | ||
187 | int packet_type; | 357 | int packet_type; |
188 | int ret; | 358 | u32 header_marker; |
189 | u8 *buffer; | ||
190 | 359 | ||
191 | buffer = kmalloc(JEILINJ_MAX_TRANSFER, GFP_KERNEL | GFP_DMA); | 360 | PDEBUG(D_STREAM, "Got %d bytes out of %d for Block 0", |
192 | if (!buffer) { | 361 | len, JEILINJ_MAX_TRANSFER); |
193 | err("Couldn't allocate USB buffer"); | 362 | if (len != JEILINJ_MAX_TRANSFER) { |
194 | goto quit_stream; | 363 | PDEBUG(D_PACK, "bad length"); |
364 | goto discard; | ||
195 | } | 365 | } |
196 | while (gspca_dev->present && gspca_dev->streaming) { | 366 | /* check if it's start of frame */ |
197 | /* | 367 | header_marker = ((u32 *)data)[0]; |
198 | * Now request data block 0. Line 0 reports the size | 368 | if (header_marker == FRAME_START) { |
199 | * to download, in blocks of size 0x200, and also tells the | 369 | sd->blocks_left = data[0x0a] - 1; |
200 | * "actual" data size, in bytes, which seems best to ignore. | 370 | PDEBUG(D_STREAM, "blocks_left = 0x%x", sd->blocks_left); |
201 | */ | ||
202 | ret = usb_bulk_msg(gspca_dev->dev, | ||
203 | usb_rcvbulkpipe(gspca_dev->dev, 0x82), | ||
204 | buffer, JEILINJ_MAX_TRANSFER, &act_len, | ||
205 | JEILINJ_DATA_TIMEOUT); | ||
206 | PDEBUG(D_STREAM, | ||
207 | "Got %d bytes out of %d for Block 0", | ||
208 | act_len, JEILINJ_MAX_TRANSFER); | ||
209 | if (ret < 0 || act_len < FRAME_HEADER_LEN) | ||
210 | goto quit_stream; | ||
211 | blocks_left = buffer[0x0a] - 1; | ||
212 | PDEBUG(D_STREAM, "blocks_left = 0x%x", blocks_left); | ||
213 | |||
214 | /* Start a new frame, and add the JPEG header, first thing */ | 371 | /* Start a new frame, and add the JPEG header, first thing */ |
215 | gspca_frame_add(gspca_dev, FIRST_PACKET, | 372 | gspca_frame_add(gspca_dev, FIRST_PACKET, |
216 | dev->jpeg_hdr, JPEG_HDR_SZ); | 373 | sd->jpeg_hdr, JPEG_HDR_SZ); |
217 | /* Toss line 0 of data block 0, keep the rest. */ | 374 | /* Toss line 0 of data block 0, keep the rest. */ |
218 | gspca_frame_add(gspca_dev, INTER_PACKET, | 375 | gspca_frame_add(gspca_dev, INTER_PACKET, |
219 | buffer + FRAME_HEADER_LEN, | 376 | data + FRAME_HEADER_LEN, |
220 | JEILINJ_MAX_TRANSFER - FRAME_HEADER_LEN); | 377 | JEILINJ_MAX_TRANSFER - FRAME_HEADER_LEN); |
221 | 378 | } else if (sd->blocks_left > 0) { | |
222 | while (blocks_left > 0) { | 379 | PDEBUG(D_STREAM, "%d blocks remaining for frame", |
223 | if (!gspca_dev->present) | 380 | sd->blocks_left); |
224 | goto quit_stream; | 381 | sd->blocks_left -= 1; |
225 | ret = usb_bulk_msg(gspca_dev->dev, | 382 | if (sd->blocks_left == 0) |
226 | usb_rcvbulkpipe(gspca_dev->dev, 0x82), | 383 | packet_type = LAST_PACKET; |
227 | buffer, JEILINJ_MAX_TRANSFER, &act_len, | 384 | else |
228 | JEILINJ_DATA_TIMEOUT); | 385 | packet_type = INTER_PACKET; |
229 | if (ret < 0 || act_len < JEILINJ_MAX_TRANSFER) | 386 | gspca_frame_add(gspca_dev, packet_type, |
230 | goto quit_stream; | 387 | data, JEILINJ_MAX_TRANSFER); |
231 | PDEBUG(D_STREAM, | 388 | } else |
232 | "%d blocks remaining for frame", blocks_left); | 389 | goto discard; |
233 | blocks_left -= 1; | 390 | return; |
234 | if (blocks_left == 0) | 391 | discard: |
235 | packet_type = LAST_PACKET; | 392 | /* Discard data until a new frame starts. */ |
236 | else | 393 | gspca_dev->last_packet_type = DISCARD_PACKET; |
237 | packet_type = INTER_PACKET; | ||
238 | gspca_frame_add(gspca_dev, packet_type, | ||
239 | buffer, JEILINJ_MAX_TRANSFER); | ||
240 | } | ||
241 | } | ||
242 | quit_stream: | ||
243 | mutex_lock(&gspca_dev->usb_lock); | ||
244 | if (gspca_dev->present) | ||
245 | jlj_stop(gspca_dev); | ||
246 | mutex_unlock(&gspca_dev->usb_lock); | ||
247 | kfree(buffer); | ||
248 | } | 394 | } |
249 | 395 | ||
250 | /* This function is called at probe time just before sd_init */ | 396 | /* This function is called at probe time just before sd_init */ |
@@ -254,78 +400,169 @@ static int sd_config(struct gspca_dev *gspca_dev, | |||
254 | struct cam *cam = &gspca_dev->cam; | 400 | struct cam *cam = &gspca_dev->cam; |
255 | struct sd *dev = (struct sd *) gspca_dev; | 401 | struct sd *dev = (struct sd *) gspca_dev; |
256 | 402 | ||
257 | dev->quality = 85; | 403 | dev->type = id->driver_info; |
258 | dev->jpegqual = 85; | 404 | gspca_dev->cam.ctrls = dev->ctrls; |
405 | dev->quality = QUALITY_DEF; | ||
406 | dev->ctrls[LIGHTFREQ].def = V4L2_CID_POWER_LINE_FREQUENCY_60HZ; | ||
407 | dev->ctrls[RED].def = RED_BALANCE_DEF; | ||
408 | dev->ctrls[GREEN].def = GREEN_BALANCE_DEF; | ||
409 | dev->ctrls[BLUE].def = BLUE_BALANCE_DEF; | ||
259 | PDEBUG(D_PROBE, | 410 | PDEBUG(D_PROBE, |
260 | "JEILINJ camera detected" | 411 | "JEILINJ camera detected" |
261 | " (vid/pid 0x%04X:0x%04X)", id->idVendor, id->idProduct); | 412 | " (vid/pid 0x%04X:0x%04X)", id->idVendor, id->idProduct); |
262 | cam->cam_mode = jlj_mode; | 413 | cam->cam_mode = jlj_mode; |
263 | cam->nmodes = 1; | 414 | cam->nmodes = ARRAY_SIZE(jlj_mode); |
264 | cam->bulk = 1; | 415 | cam->bulk = 1; |
265 | /* We don't use the buffer gspca allocates so make it small. */ | 416 | cam->bulk_nurbs = 1; |
266 | cam->bulk_size = 32; | 417 | cam->bulk_size = JEILINJ_MAX_TRANSFER; |
267 | INIT_WORK(&dev->work_struct, jlj_dostream); | ||
268 | return 0; | 418 | return 0; |
269 | } | 419 | } |
270 | 420 | ||
271 | /* called on streamoff with alt==0 and on disconnect */ | 421 | static void sd_stopN(struct gspca_dev *gspca_dev) |
272 | /* the usb_lock is held at entry - restore on exit */ | ||
273 | static void sd_stop0(struct gspca_dev *gspca_dev) | ||
274 | { | 422 | { |
275 | struct sd *dev = (struct sd *) gspca_dev; | 423 | int i; |
424 | u8 *buf; | ||
425 | u8 stop_commands[][2] = { | ||
426 | {0x71, 0x00}, | ||
427 | {0x70, 0x09}, | ||
428 | {0x71, 0x80}, | ||
429 | {0x70, 0x05} | ||
430 | }; | ||
431 | |||
432 | for (;;) { | ||
433 | /* get the image remaining blocks */ | ||
434 | usb_bulk_msg(gspca_dev->dev, | ||
435 | gspca_dev->urb[0]->pipe, | ||
436 | gspca_dev->urb[0]->transfer_buffer, | ||
437 | JEILINJ_MAX_TRANSFER, NULL, | ||
438 | JEILINJ_DATA_TIMEOUT); | ||
439 | |||
440 | /* search for 0xff 0xd9 (EOF for JPEG) */ | ||
441 | i = 0; | ||
442 | buf = gspca_dev->urb[0]->transfer_buffer; | ||
443 | while ((i < (JEILINJ_MAX_TRANSFER - 1)) && | ||
444 | ((buf[i] != 0xff) || (buf[i+1] != 0xd9))) | ||
445 | i++; | ||
276 | 446 | ||
277 | /* wait for the work queue to terminate */ | 447 | if (i != (JEILINJ_MAX_TRANSFER - 1)) |
278 | mutex_unlock(&gspca_dev->usb_lock); | 448 | /* last remaining block found */ |
279 | /* This waits for jlj_dostream to finish */ | 449 | break; |
280 | destroy_workqueue(dev->work_thread); | 450 | } |
281 | dev->work_thread = NULL; | 451 | |
282 | mutex_lock(&gspca_dev->usb_lock); | 452 | for (i = 0; i < ARRAY_SIZE(stop_commands); i++) |
453 | jlj_write2(gspca_dev, stop_commands[i]); | ||
283 | } | 454 | } |
284 | 455 | ||
285 | /* this function is called at probe and resume time */ | 456 | /* this function is called at probe and resume time */ |
286 | static int sd_init(struct gspca_dev *gspca_dev) | 457 | static int sd_init(struct gspca_dev *gspca_dev) |
287 | { | 458 | { |
288 | return 0; | 459 | return gspca_dev->usb_err; |
289 | } | 460 | } |
290 | 461 | ||
291 | /* Set up for getting frames. */ | 462 | /* Set up for getting frames. */ |
292 | static int sd_start(struct gspca_dev *gspca_dev) | 463 | static int sd_start(struct gspca_dev *gspca_dev) |
293 | { | 464 | { |
294 | struct sd *dev = (struct sd *) gspca_dev; | 465 | struct sd *dev = (struct sd *) gspca_dev; |
295 | int ret; | ||
296 | 466 | ||
297 | /* create the JPEG header */ | 467 | /* create the JPEG header */ |
298 | jpeg_define(dev->jpeg_hdr, gspca_dev->height, gspca_dev->width, | 468 | jpeg_define(dev->jpeg_hdr, gspca_dev->height, gspca_dev->width, |
299 | 0x21); /* JPEG 422 */ | 469 | 0x21); /* JPEG 422 */ |
300 | jpeg_set_qual(dev->jpeg_hdr, dev->quality); | 470 | jpeg_set_qual(dev->jpeg_hdr, dev->quality); |
301 | PDEBUG(D_STREAM, "Start streaming at 320x240"); | 471 | PDEBUG(D_STREAM, "Start streaming at %dx%d", |
302 | ret = jlj_start(gspca_dev); | 472 | gspca_dev->height, gspca_dev->width); |
303 | if (ret < 0) { | 473 | jlj_start(gspca_dev); |
304 | PDEBUG(D_ERR, "Start streaming command failed"); | 474 | return gspca_dev->usb_err; |
305 | return ret; | ||
306 | } | ||
307 | /* Start the workqueue function to do the streaming */ | ||
308 | dev->work_thread = create_singlethread_workqueue(MODULE_NAME); | ||
309 | queue_work(dev->work_thread, &dev->work_struct); | ||
310 | |||
311 | return 0; | ||
312 | } | 475 | } |
313 | 476 | ||
314 | /* Table of supported USB devices */ | 477 | /* Table of supported USB devices */ |
315 | static const struct usb_device_id device_table[] = { | 478 | static const struct usb_device_id device_table[] = { |
316 | {USB_DEVICE(0x0979, 0x0280)}, | 479 | {USB_DEVICE(0x0979, 0x0280), .driver_info = SAKAR_57379}, |
480 | {USB_DEVICE(0x0979, 0x0270), .driver_info = SPORTSCAM_DV15}, | ||
317 | {} | 481 | {} |
318 | }; | 482 | }; |
319 | 483 | ||
320 | MODULE_DEVICE_TABLE(usb, device_table); | 484 | MODULE_DEVICE_TABLE(usb, device_table); |
321 | 485 | ||
486 | static int sd_querymenu(struct gspca_dev *gspca_dev, | ||
487 | struct v4l2_querymenu *menu) | ||
488 | { | ||
489 | switch (menu->id) { | ||
490 | case V4L2_CID_POWER_LINE_FREQUENCY: | ||
491 | switch (menu->index) { | ||
492 | case 0: /* V4L2_CID_POWER_LINE_FREQUENCY_DISABLED */ | ||
493 | strcpy((char *) menu->name, "disable"); | ||
494 | return 0; | ||
495 | case 1: /* V4L2_CID_POWER_LINE_FREQUENCY_50HZ */ | ||
496 | strcpy((char *) menu->name, "50 Hz"); | ||
497 | return 0; | ||
498 | case 2: /* V4L2_CID_POWER_LINE_FREQUENCY_60HZ */ | ||
499 | strcpy((char *) menu->name, "60 Hz"); | ||
500 | return 0; | ||
501 | } | ||
502 | break; | ||
503 | } | ||
504 | return -EINVAL; | ||
505 | } | ||
506 | |||
507 | static int sd_set_jcomp(struct gspca_dev *gspca_dev, | ||
508 | struct v4l2_jpegcompression *jcomp) | ||
509 | { | ||
510 | struct sd *sd = (struct sd *) gspca_dev; | ||
511 | |||
512 | if (jcomp->quality < QUALITY_MIN) | ||
513 | sd->quality = QUALITY_MIN; | ||
514 | else if (jcomp->quality > QUALITY_MAX) | ||
515 | sd->quality = QUALITY_MAX; | ||
516 | else | ||
517 | sd->quality = jcomp->quality; | ||
518 | if (gspca_dev->streaming) { | ||
519 | jpeg_set_qual(sd->jpeg_hdr, sd->quality); | ||
520 | setcamquality(gspca_dev); | ||
521 | } | ||
522 | return 0; | ||
523 | } | ||
524 | |||
525 | static int sd_get_jcomp(struct gspca_dev *gspca_dev, | ||
526 | struct v4l2_jpegcompression *jcomp) | ||
527 | { | ||
528 | struct sd *sd = (struct sd *) gspca_dev; | ||
529 | |||
530 | memset(jcomp, 0, sizeof *jcomp); | ||
531 | jcomp->quality = sd->quality; | ||
532 | jcomp->jpeg_markers = V4L2_JPEG_MARKER_DHT | ||
533 | | V4L2_JPEG_MARKER_DQT; | ||
534 | return 0; | ||
535 | } | ||
536 | |||
537 | |||
322 | /* sub-driver description */ | 538 | /* sub-driver description */ |
323 | static const struct sd_desc sd_desc = { | 539 | static const struct sd_desc sd_desc_sakar_57379 = { |
324 | .name = MODULE_NAME, | 540 | .name = MODULE_NAME, |
325 | .config = sd_config, | 541 | .config = sd_config, |
326 | .init = sd_init, | 542 | .init = sd_init, |
327 | .start = sd_start, | 543 | .start = sd_start, |
328 | .stop0 = sd_stop0, | 544 | .stopN = sd_stopN, |
545 | .pkt_scan = sd_pkt_scan, | ||
546 | }; | ||
547 | |||
548 | /* sub-driver description */ | ||
549 | static const struct sd_desc sd_desc_sportscam_dv15 = { | ||
550 | .name = MODULE_NAME, | ||
551 | .config = sd_config, | ||
552 | .init = sd_init, | ||
553 | .start = sd_start, | ||
554 | .stopN = sd_stopN, | ||
555 | .pkt_scan = sd_pkt_scan, | ||
556 | .ctrls = sd_ctrls, | ||
557 | .nctrls = ARRAY_SIZE(sd_ctrls), | ||
558 | .querymenu = sd_querymenu, | ||
559 | .get_jcomp = sd_get_jcomp, | ||
560 | .set_jcomp = sd_set_jcomp, | ||
561 | }; | ||
562 | |||
563 | static const struct sd_desc *sd_desc[2] = { | ||
564 | &sd_desc_sakar_57379, | ||
565 | &sd_desc_sportscam_dv15 | ||
329 | }; | 566 | }; |
330 | 567 | ||
331 | /* -- device connect -- */ | 568 | /* -- device connect -- */ |
@@ -333,7 +570,7 @@ static int sd_probe(struct usb_interface *intf, | |||
333 | const struct usb_device_id *id) | 570 | const struct usb_device_id *id) |
334 | { | 571 | { |
335 | return gspca_dev_probe(intf, id, | 572 | return gspca_dev_probe(intf, id, |
336 | &sd_desc, | 573 | sd_desc[id->driver_info], |
337 | sizeof(struct sd), | 574 | sizeof(struct sd), |
338 | THIS_MODULE); | 575 | THIS_MODULE); |
339 | } | 576 | } |