aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media
diff options
context:
space:
mode:
authorTheodore Kilgore <kilgota@auburn.edu>2009-08-03 03:13:23 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2009-09-12 11:18:54 -0400
commit3040b043423c1726a14595d500f6409070b1e722 (patch)
treeba75dd6b0a17e5d4ce4f11c16b499414f09b976d /drivers/media
parent9d7530d53d6cd8b50efc8dcecad4febe8ae53fd4 (diff)
V4L/DVB (12459): gspca - jeilinj: New subdriver for Jeilin chip.
Signed-off-by: Theodore Kilgore <kilgota@auburn.edu> Signed-off-by: Jean-Francois Moine <moinejf@free.fr> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media')
-rw-r--r--drivers/media/video/gspca/Kconfig9
-rw-r--r--drivers/media/video/gspca/Makefile2
-rw-r--r--drivers/media/video/gspca/jeilinj.c388
3 files changed, 399 insertions, 0 deletions
diff --git a/drivers/media/video/gspca/Kconfig b/drivers/media/video/gspca/Kconfig
index f114dd1507c2..e800c22a9a89 100644
--- a/drivers/media/video/gspca/Kconfig
+++ b/drivers/media/video/gspca/Kconfig
@@ -47,6 +47,15 @@ config USB_GSPCA_FINEPIX
47 To compile this driver as a module, choose M here: the 47 To compile this driver as a module, choose M here: the
48 module will be called gspca_finepix. 48 module will be called gspca_finepix.
49 49
50config USB_GSPCA_JEILINJ
51 tristate "Jeilin JPEG USB V4L2 driver"
52 depends on VIDEO_V4L2 && USB_GSPCA
53 help
54 Say Y here if you want support for cameras based on this Jeilin chip.
55
56 To compile this driver as a module, choose M here: the
57 module will be called gspca_jeilinj.
58
50config USB_GSPCA_MARS 59config USB_GSPCA_MARS
51 tristate "Mars USB Camera Driver" 60 tristate "Mars USB Camera Driver"
52 depends on VIDEO_V4L2 && USB_GSPCA 61 depends on VIDEO_V4L2 && USB_GSPCA
diff --git a/drivers/media/video/gspca/Makefile b/drivers/media/video/gspca/Makefile
index f6d3b86e9ad5..035616b5e867 100644
--- a/drivers/media/video/gspca/Makefile
+++ b/drivers/media/video/gspca/Makefile
@@ -2,6 +2,7 @@ obj-$(CONFIG_USB_GSPCA) += gspca_main.o
2obj-$(CONFIG_USB_GSPCA_CONEX) += gspca_conex.o 2obj-$(CONFIG_USB_GSPCA_CONEX) += gspca_conex.o
3obj-$(CONFIG_USB_GSPCA_ETOMS) += gspca_etoms.o 3obj-$(CONFIG_USB_GSPCA_ETOMS) += gspca_etoms.o
4obj-$(CONFIG_USB_GSPCA_FINEPIX) += gspca_finepix.o 4obj-$(CONFIG_USB_GSPCA_FINEPIX) += gspca_finepix.o
5obj-$(CONFIG_USB_GSPCA_JEILINJ) += gspca_jeilinj.o
5obj-$(CONFIG_USB_GSPCA_MARS) += gspca_mars.o 6obj-$(CONFIG_USB_GSPCA_MARS) += gspca_mars.o
6obj-$(CONFIG_USB_GSPCA_MR97310A) += gspca_mr97310a.o 7obj-$(CONFIG_USB_GSPCA_MR97310A) += gspca_mr97310a.o
7obj-$(CONFIG_USB_GSPCA_OV519) += gspca_ov519.o 8obj-$(CONFIG_USB_GSPCA_OV519) += gspca_ov519.o
@@ -30,6 +31,7 @@ gspca_main-objs := gspca.o
30gspca_conex-objs := conex.o 31gspca_conex-objs := conex.o
31gspca_etoms-objs := etoms.o 32gspca_etoms-objs := etoms.o
32gspca_finepix-objs := finepix.o 33gspca_finepix-objs := finepix.o
34gspca_jeilinj-objs := jeilinj.o
33gspca_mars-objs := mars.o 35gspca_mars-objs := mars.o
34gspca_mr97310a-objs := mr97310a.o 36gspca_mr97310a-objs := mr97310a.o
35gspca_ov519-objs := ov519.o 37gspca_ov519-objs := ov519.o
diff --git a/drivers/media/video/gspca/jeilinj.c b/drivers/media/video/gspca/jeilinj.c
new file mode 100644
index 000000000000..dbfa3ed6e8ef
--- /dev/null
+++ b/drivers/media/video/gspca/jeilinj.c
@@ -0,0 +1,388 @@
1/*
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
8 *
9 * 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
11 * the Free Software Foundation; either version 2 of the License, or
12 * any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23
24#define MODULE_NAME "jeilinj"
25
26#include <linux/workqueue.h>
27#include "gspca.h"
28#include "jpeg.h"
29
30MODULE_AUTHOR("Theodore Kilgore <kilgota@auburn.edu>");
31MODULE_DESCRIPTION("GSPCA/JEILINJ USB Camera Driver");
32MODULE_LICENSE("GPL");
33
34/* Default timeouts, in ms */
35#define JEILINJ_CMD_TIMEOUT 500
36#define JEILINJ_DATA_TIMEOUT 1000
37
38/* Maximum transfer size to use. */
39#define JEILINJ_MAX_TRANSFER 0x200
40
41#define FRAME_HEADER_LEN 0x10
42
43/* Structure to hold all of our device specific stuff */
44struct sd {
45 struct gspca_dev gspca_dev; /* !! must be the first item */
46 const struct v4l2_pix_format *cap_mode;
47 /* Driver stuff */
48 struct work_struct work_struct;
49 struct workqueue_struct *work_thread;
50 u8 quality; /* image quality */
51 u8 jpegqual; /* webcam quality */
52 u8 *jpeg_hdr;
53};
54
55 struct jlj_command {
56 unsigned char instruction[2];
57 unsigned char ack_wanted;
58 };
59
60/* AFAICT these cameras will only do 320x240. */
61static struct v4l2_pix_format jlj_mode[] = {
62 { 320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
63 .bytesperline = 320,
64 .sizeimage = 320 * 240,
65 .colorspace = V4L2_COLORSPACE_JPEG,
66 .priv = 0}
67};
68
69/*
70 * cam uses endpoint 0x03 to send commands, 0x84 for read commands,
71 * and 0x82 for bulk transfer.
72 */
73
74/* All commands are two bytes only */
75static int jlj_write2(struct gspca_dev *gspca_dev, unsigned char *command)
76{
77 int retval;
78
79 memcpy(gspca_dev->usb_buf, command, 2);
80 retval = usb_bulk_msg(gspca_dev->dev,
81 usb_sndbulkpipe(gspca_dev->dev, 3),
82 gspca_dev->usb_buf, 2, NULL, 500);
83 if (retval < 0)
84 PDEBUG(D_ERR, "command write [%02x] error %d",
85 gspca_dev->usb_buf[0], retval);
86 return retval;
87}
88
89/* Responses are one byte only */
90static int jlj_read1(struct gspca_dev *gspca_dev, unsigned char response)
91{
92 int retval;
93
94 retval = usb_bulk_msg(gspca_dev->dev,
95 usb_rcvbulkpipe(gspca_dev->dev, 0x84),
96 gspca_dev->usb_buf, 1, NULL, 500);
97 response = gspca_dev->usb_buf[0];
98 if (retval < 0)
99 PDEBUG(D_ERR, "read command [%02x] error %d",
100 gspca_dev->usb_buf[0], retval);
101 return retval;
102}
103
104static int jlj_start(struct gspca_dev *gspca_dev)
105{
106 int i;
107 int retval = -1;
108 u8 response = 0xff;
109 struct jlj_command start_commands[] = {
110 {{0x71, 0x81}, 0},
111 {{0x70, 0x05}, 0},
112 {{0x95, 0x70}, 1},
113 {{0x71, 0x81}, 0},
114 {{0x70, 0x04}, 0},
115 {{0x95, 0x70}, 1},
116 {{0x71, 0x00}, 0},
117 {{0x70, 0x08}, 0},
118 {{0x95, 0x70}, 1},
119 {{0x94, 0x02}, 0},
120 {{0xde, 0x24}, 0},
121 {{0x94, 0x02}, 0},
122 {{0xdd, 0xf0}, 0},
123 {{0x94, 0x02}, 0},
124 {{0xe3, 0x2c}, 0},
125 {{0x94, 0x02}, 0},
126 {{0xe4, 0x00}, 0},
127 {{0x94, 0x02}, 0},
128 {{0xe5, 0x00}, 0},
129 {{0x94, 0x02}, 0},
130 {{0xe6, 0x2c}, 0},
131 {{0x94, 0x03}, 0},
132 {{0xaa, 0x00}, 0},
133 {{0x71, 0x1e}, 0},
134 {{0x70, 0x06}, 0},
135 {{0x71, 0x80}, 0},
136 {{0x70, 0x07}, 0}
137 };
138 for (i = 0; i < ARRAY_SIZE(start_commands); i++) {
139 retval = jlj_write2(gspca_dev, start_commands[i].instruction);
140 if (retval < 0)
141 return retval;
142 if (start_commands[i].ack_wanted)
143 retval = jlj_read1(gspca_dev, response);
144 if (retval < 0)
145 return retval;
146 }
147 PDEBUG(D_ERR, "jlj_start retval is %d", retval);
148 return retval;
149}
150
151static int jlj_stop(struct gspca_dev *gspca_dev)
152{
153 int i;
154 int retval;
155 struct jlj_command stop_commands[] = {
156 {{0x71, 0x00}, 0},
157 {{0x70, 0x09}, 0},
158 {{0x71, 0x80}, 0},
159 {{0x70, 0x05}, 0}
160 };
161 for (i = 0; i < ARRAY_SIZE(stop_commands); i++) {
162 retval = jlj_write2(gspca_dev, stop_commands[i].instruction);
163 if (retval < 0)
164 return retval;
165 }
166 return retval;
167}
168
169/* This function is called as a workqueue function and runs whenever the camera
170 * is streaming data. Because it is a workqueue function it is allowed to sleep
171 * so we can use synchronous USB calls. To avoid possible collisions with other
172 * threads attempting to use the camera's USB interface the gspca usb_lock is
173 * used when performing the one USB control operation inside the workqueue,
174 * which tells the camera to close the stream. In practice the only thing
175 * which needs to be protected against is the usb_set_interface call that
176 * gspca makes during stream_off. Otherwise the camera doesn't provide any
177 * controls that the user could try to change.
178 */
179
180static void jlj_dostream(struct work_struct *work)
181{
182 struct sd *dev = container_of(work, struct sd, work_struct);
183 struct gspca_dev *gspca_dev = &dev->gspca_dev;
184 struct gspca_frame *frame;
185 int blocks_left; /* 0x200-sized blocks remaining in current frame. */
186 int size_in_blocks;
187 int act_len;
188 int discarding = 0; /* true if we failed to get space for frame. */
189 int packet_type;
190 int ret;
191 u8 *buffer;
192
193 buffer = kmalloc(JEILINJ_MAX_TRANSFER, GFP_KERNEL | GFP_DMA);
194 if (!buffer) {
195 PDEBUG(D_ERR, "Couldn't allocate USB buffer");
196 goto quit_stream;
197 }
198 while (gspca_dev->present && gspca_dev->streaming) {
199 if (!gspca_dev->present)
200 goto quit_stream;
201 /* Start a new frame, and add the JPEG header, first thing */
202 frame = gspca_get_i_frame(gspca_dev);
203 if (frame && !discarding)
204 gspca_frame_add(gspca_dev, FIRST_PACKET, frame,
205 dev->jpeg_hdr, JPEG_HDR_SZ);
206 else
207 discarding = 1;
208 /*
209 * Now request data block 0. Line 0 reports the size
210 * to download, in blocks of size 0x200, and also tells the
211 * "actual" data size, in bytes, which seems best to ignore.
212 */
213 ret = usb_bulk_msg(gspca_dev->dev,
214 usb_rcvbulkpipe(gspca_dev->dev, 0x82),
215 buffer, JEILINJ_MAX_TRANSFER, &act_len,
216 JEILINJ_DATA_TIMEOUT);
217 PDEBUG(D_STREAM,
218 "Got %d bytes out of %d for Block 0",
219 act_len, JEILINJ_MAX_TRANSFER);
220 if (ret < 0 || act_len < FRAME_HEADER_LEN)
221 goto quit_stream;
222 size_in_blocks = buffer[0x0a];
223 blocks_left = buffer[0x0a] - 1;
224 PDEBUG(D_STREAM, "blocks_left = 0x%x", blocks_left);
225 packet_type = INTER_PACKET;
226 if (frame && !discarding)
227 /* Toss line 0 of data block 0, keep the rest. */
228 gspca_frame_add(gspca_dev, packet_type,
229 frame, buffer + FRAME_HEADER_LEN,
230 JEILINJ_MAX_TRANSFER - FRAME_HEADER_LEN);
231 else
232 discarding = 1;
233 while (blocks_left > 0) {
234 if (!gspca_dev->present)
235 goto quit_stream;
236 ret = usb_bulk_msg(gspca_dev->dev,
237 usb_rcvbulkpipe(gspca_dev->dev, 0x82),
238 buffer, JEILINJ_MAX_TRANSFER, &act_len,
239 JEILINJ_DATA_TIMEOUT);
240 if (ret < 0 || act_len < JEILINJ_MAX_TRANSFER)
241 goto quit_stream;
242 PDEBUG(D_STREAM,
243 "%d blocks remaining for frame", blocks_left);
244 blocks_left -= 1;
245 if (blocks_left == 0)
246 packet_type = LAST_PACKET;
247 else
248 packet_type = INTER_PACKET;
249 if (frame && !discarding)
250 gspca_frame_add(gspca_dev, packet_type,
251 frame, buffer,
252 JEILINJ_MAX_TRANSFER);
253 else
254 discarding = 1;
255 }
256 }
257quit_stream:
258 mutex_lock(&gspca_dev->usb_lock);
259 if (gspca_dev->present)
260 jlj_stop(gspca_dev);
261 mutex_unlock(&gspca_dev->usb_lock);
262 kfree(buffer);
263}
264
265/* This function is called at probe time just before sd_init */
266static int sd_config(struct gspca_dev *gspca_dev,
267 const struct usb_device_id *id)
268{
269 struct cam *cam = &gspca_dev->cam;
270 struct sd *dev = (struct sd *) gspca_dev;
271
272 dev->quality = 85;
273 dev->jpegqual = 85;
274 PDEBUG(D_PROBE,
275 "JEILINJ camera detected"
276 " (vid/pid 0x%04X:0x%04X)", id->idVendor, id->idProduct);
277 cam->cam_mode = jlj_mode;
278 cam->nmodes = 1;
279 cam->bulk = 1;
280 /* We don't use the buffer gspca allocates so make it small. */
281 cam->bulk_size = 32;
282 INIT_WORK(&dev->work_struct, jlj_dostream);
283 return 0;
284}
285
286/* called on streamoff with alt==0 and on disconnect */
287/* the usb_lock is held at entry - restore on exit */
288static void sd_stop0(struct gspca_dev *gspca_dev)
289{
290 struct sd *dev = (struct sd *) gspca_dev;
291
292 /* wait for the work queue to terminate */
293 mutex_unlock(&gspca_dev->usb_lock);
294 /* This waits for jlj_dostream to finish */
295 destroy_workqueue(dev->work_thread);
296 dev->work_thread = NULL;
297 mutex_lock(&gspca_dev->usb_lock);
298 kfree(dev->jpeg_hdr);
299}
300
301/* this function is called at probe and resume time */
302static int sd_init(struct gspca_dev *gspca_dev)
303{
304 return 0;
305}
306
307/* Set up for getting frames. */
308static int sd_start(struct gspca_dev *gspca_dev)
309{
310 struct sd *dev = (struct sd *) gspca_dev;
311 int ret;
312
313 /* create the JPEG header */
314 dev->jpeg_hdr = kmalloc(JPEG_HDR_SZ, GFP_KERNEL);
315 jpeg_define(dev->jpeg_hdr, gspca_dev->height, gspca_dev->width,
316 0x21); /* JPEG 422 */
317 jpeg_set_qual(dev->jpeg_hdr, dev->quality);
318 PDEBUG(D_STREAM, "Start streaming at 320x240");
319 ret = jlj_start(gspca_dev);
320 if (ret < 0) {
321 PDEBUG(D_ERR, "Start streaming command failed");
322 return ret;
323 }
324 /* Start the workqueue function to do the streaming */
325 dev->work_thread = create_singlethread_workqueue(MODULE_NAME);
326 queue_work(dev->work_thread, &dev->work_struct);
327
328 return 0;
329}
330
331/* Table of supported USB devices */
332static const __devinitdata struct usb_device_id device_table[] = {
333 {USB_DEVICE(0x0979, 0x0280)},
334 {}
335};
336
337MODULE_DEVICE_TABLE(usb, device_table);
338
339/* sub-driver description */
340static const struct sd_desc sd_desc = {
341 .name = MODULE_NAME,
342 .config = sd_config,
343 .init = sd_init,
344 .start = sd_start,
345 .stop0 = sd_stop0,
346};
347
348/* -- device connect -- */
349static int sd_probe(struct usb_interface *intf,
350 const struct usb_device_id *id)
351{
352 return gspca_dev_probe(intf, id,
353 &sd_desc,
354 sizeof(struct sd),
355 THIS_MODULE);
356}
357
358static struct usb_driver sd_driver = {
359 .name = MODULE_NAME,
360 .id_table = device_table,
361 .probe = sd_probe,
362 .disconnect = gspca_disconnect,
363#ifdef CONFIG_PM
364 .suspend = gspca_suspend,
365 .resume = gspca_resume,
366#endif
367};
368
369/* -- module insert / remove -- */
370static int __init sd_mod_init(void)
371{
372 int ret;
373
374 ret = usb_register(&sd_driver);
375 if (ret < 0)
376 return ret;
377 PDEBUG(D_PROBE, "registered");
378 return 0;
379}
380
381static void __exit sd_mod_exit(void)
382{
383 usb_deregister(&sd_driver);
384 PDEBUG(D_PROBE, "deregistered");
385}
386
387module_init(sd_mod_init);
388module_exit(sd_mod_exit);