blob: 031f7195ce0dca39f72b60193b83bc7fbafe7cb1 [file] [log] [blame]
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001/*
2 * Mars-Semi MR97311A library
3 * Copyright (C) 2005 <bradlch@hotmail.com>
4 *
5 * V4L2 by Jean-Francois Moine <http://moinejf.free.fr>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22#define MODULE_NAME "mars"
23
24#include "gspca.h"
25#include "jpeg.h"
26
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030027MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
28MODULE_DESCRIPTION("GSPCA/Mars USB Camera Driver");
29MODULE_LICENSE("GPL");
30
31/* specific webcam descriptor */
32struct sd {
33 struct gspca_dev gspca_dev; /* !! must be the first item */
Jean-Francois Moinea0306bf2009-01-08 16:29:38 -030034
35 u8 brightness;
36 u8 colors;
37 u8 gamma;
38 u8 sharpness;
Jean-Francois Moine71cb2762009-03-03 05:33:41 -030039 u8 quality;
Jean-Francois Moine77ac0ba2009-03-02 06:40:52 -030040#define QUALITY_MIN 40
41#define QUALITY_MAX 70
42#define QUALITY_DEF 50
Jean-Francois Moine71cb2762009-03-03 05:33:41 -030043
Jean-François Moine9a731a32010-06-04 05:26:42 -030044 u8 jpeg_hdr[JPEG_HDR_SZ];
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030045};
46
47/* V4L2 controls supported by the driver */
Jean-Francois Moinea0306bf2009-01-08 16:29:38 -030048static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
49static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
50static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val);
51static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val);
52static int sd_setgamma(struct gspca_dev *gspca_dev, __s32 val);
53static int sd_getgamma(struct gspca_dev *gspca_dev, __s32 *val);
54static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val);
55static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val);
56
Marton Nemeth7e64dc42009-12-30 09:12:41 -030057static const struct ctrl sd_ctrls[] = {
Jean-Francois Moinea0306bf2009-01-08 16:29:38 -030058 {
59 {
60 .id = V4L2_CID_BRIGHTNESS,
61 .type = V4L2_CTRL_TYPE_INTEGER,
62 .name = "Brightness",
63 .minimum = 0,
64 .maximum = 30,
65 .step = 1,
66#define BRIGHTNESS_DEF 15
67 .default_value = BRIGHTNESS_DEF,
68 },
69 .set = sd_setbrightness,
70 .get = sd_getbrightness,
71 },
72 {
73 {
74 .id = V4L2_CID_SATURATION,
75 .type = V4L2_CTRL_TYPE_INTEGER,
76 .name = "Color",
Jean-Francois Moine253bae52009-02-28 08:09:24 -030077 .minimum = 1,
78 .maximum = 255,
Jean-Francois Moinea0306bf2009-01-08 16:29:38 -030079 .step = 1,
Jean-Francois Moine253bae52009-02-28 08:09:24 -030080#define COLOR_DEF 200
Jean-Francois Moinea0306bf2009-01-08 16:29:38 -030081 .default_value = COLOR_DEF,
82 },
83 .set = sd_setcolors,
84 .get = sd_getcolors,
85 },
86 {
87 {
88 .id = V4L2_CID_GAMMA,
89 .type = V4L2_CTRL_TYPE_INTEGER,
90 .name = "Gamma",
91 .minimum = 0,
92 .maximum = 3,
93 .step = 1,
94#define GAMMA_DEF 1
95 .default_value = GAMMA_DEF,
96 },
97 .set = sd_setgamma,
98 .get = sd_getgamma,
99 },
100 {
101 {
102 .id = V4L2_CID_SHARPNESS,
103 .type = V4L2_CTRL_TYPE_INTEGER,
104 .name = "Sharpness",
105 .minimum = 0,
106 .maximum = 2,
107 .step = 1,
108#define SHARPNESS_DEF 1
109 .default_value = SHARPNESS_DEF,
110 },
111 .set = sd_setsharpness,
112 .get = sd_getsharpness,
113 },
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300114};
115
Jean-Francois Moinecc611b82008-12-29 07:49:41 -0300116static const struct v4l2_pix_format vga_mode[] = {
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300117 {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
118 .bytesperline = 320,
Jean-Francois Moinea0306bf2009-01-08 16:29:38 -0300119 .sizeimage = 320 * 240 * 3 / 8 + 590,
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300120 .colorspace = V4L2_COLORSPACE_JPEG,
121 .priv = 2},
122 {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
123 .bytesperline = 640,
124 .sizeimage = 640 * 480 * 3 / 8 + 590,
125 .colorspace = V4L2_COLORSPACE_JPEG,
126 .priv = 1},
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300127};
128
Jean-Francois Moinea0306bf2009-01-08 16:29:38 -0300129static const __u8 mi_data[0x20] = {
130/* 01 02 03 04 05 06 07 08 */
131 0x48, 0x22, 0x01, 0x47, 0x10, 0x00, 0x00, 0x00,
132/* 09 0a 0b 0c 0d 0e 0f 10 */
133 0x00, 0x01, 0x30, 0x01, 0x30, 0x01, 0x30, 0x01,
134/* 11 12 13 14 15 16 17 18 */
135 0x30, 0x00, 0x04, 0x00, 0x06, 0x01, 0xe2, 0x02,
136/* 19 1a 1b 1c 1d 1e 1f 20 */
137 0x82, 0x00, 0x20, 0x17, 0x80, 0x08, 0x0c, 0x00
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300138};
139
Jean-Francois Moinea0306bf2009-01-08 16:29:38 -0300140/* write <len> bytes from gspca_dev->usb_buf */
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300141static int reg_w(struct gspca_dev *gspca_dev,
Jean-Francois Moinea0306bf2009-01-08 16:29:38 -0300142 int len)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300143{
Jean-Francois Moinea0306bf2009-01-08 16:29:38 -0300144 int alen, ret;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300145
Jean-Francois Moinea0306bf2009-01-08 16:29:38 -0300146 ret = usb_bulk_msg(gspca_dev->dev,
147 usb_sndbulkpipe(gspca_dev->dev, 4),
148 gspca_dev->usb_buf,
149 len,
150 &alen,
151 500); /* timeout in milliseconds */
152 if (ret < 0)
153 PDEBUG(D_ERR, "reg write [%02x] error %d",
154 gspca_dev->usb_buf[0], ret);
155 return ret;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300156}
157
Jean-Francois Moinea0306bf2009-01-08 16:29:38 -0300158static void mi_w(struct gspca_dev *gspca_dev,
159 u8 addr,
160 u8 value)
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300161{
162 gspca_dev->usb_buf[0] = 0x1f;
163 gspca_dev->usb_buf[1] = 0; /* control byte */
Jean-Francois Moinea0306bf2009-01-08 16:29:38 -0300164 gspca_dev->usb_buf[2] = addr;
165 gspca_dev->usb_buf[3] = value;
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300166
Jean-Francois Moinea0306bf2009-01-08 16:29:38 -0300167 reg_w(gspca_dev, 4);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300168}
169
170/* this function is called at probe time */
171static int sd_config(struct gspca_dev *gspca_dev,
172 const struct usb_device_id *id)
173{
Jean-Francois Moinea0306bf2009-01-08 16:29:38 -0300174 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300175 struct cam *cam;
176
177 cam = &gspca_dev->cam;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300178 cam->cam_mode = vga_mode;
Julia Lawall80297122008-11-12 23:18:21 -0300179 cam->nmodes = ARRAY_SIZE(vga_mode);
Jean-Francois Moinea0306bf2009-01-08 16:29:38 -0300180 sd->brightness = BRIGHTNESS_DEF;
181 sd->colors = COLOR_DEF;
182 sd->gamma = GAMMA_DEF;
183 sd->sharpness = SHARPNESS_DEF;
Jean-Francois Moine77ac0ba2009-03-02 06:40:52 -0300184 sd->quality = QUALITY_DEF;
Jean-Francois Moine625deb32009-01-15 06:11:49 -0300185 gspca_dev->nbalt = 9; /* use the altsetting 08 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300186 return 0;
187}
188
Jean-Francois Moine012d6b02008-09-03 17:12:16 -0300189/* this function is called at probe and resume time */
190static int sd_init(struct gspca_dev *gspca_dev)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300191{
192 return 0;
193}
194
Jean-Francois Moine72ab97c2008-09-20 06:39:08 -0300195static int sd_start(struct gspca_dev *gspca_dev)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300196{
Jean-Francois Moinea0306bf2009-01-08 16:29:38 -0300197 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300198 int err_code;
Jean-Francois Moinea0306bf2009-01-08 16:29:38 -0300199 u8 *data;
Jean-Francois Moine253bae52009-02-28 08:09:24 -0300200 int i;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300201
Jean-Francois Moine71cb2762009-03-03 05:33:41 -0300202 /* create the JPEG header */
Jean-Francois Moine71cb2762009-03-03 05:33:41 -0300203 jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width,
204 0x21); /* JPEG 422 */
205 jpeg_set_qual(sd->jpeg_hdr, sd->quality);
206
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300207 data = gspca_dev->usb_buf;
Jean-Francois Moinea0306bf2009-01-08 16:29:38 -0300208
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300209 data[0] = 0x01; /* address */
210 data[1] = 0x01;
Jean-Francois Moinea0306bf2009-01-08 16:29:38 -0300211 err_code = reg_w(gspca_dev, 2);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300212 if (err_code < 0)
Jean-Francois Moine72ab97c2008-09-20 06:39:08 -0300213 return err_code;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300214
215 /*
216 Initialize the MR97113 chip register
217 */
218 data[0] = 0x00; /* address */
219 data[1] = 0x0c | 0x01; /* reg 0 */
220 data[2] = 0x01; /* reg 1 */
Jean-Francois Moinea0306bf2009-01-08 16:29:38 -0300221 data[3] = gspca_dev->width / 8; /* h_size , reg 2 */
222 data[4] = gspca_dev->height / 8; /* v_size , reg 3 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300223 data[5] = 0x30; /* reg 4, MI, PAS5101 :
224 * 0x30 for 24mhz , 0x28 for 12mhz */
Jean-Francois Moinea0306bf2009-01-08 16:29:38 -0300225 data[6] = 0x02; /* reg 5, H start - was 0x04 */
226 data[7] = sd->gamma * 0x40; /* reg 0x06: gamma */
227 data[8] = 0x01; /* reg 7, V start - was 0x03 */
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300228/* if (h_size == 320 ) */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300229/* data[9]= 0x56; * reg 8, 24MHz, 2:1 scale down */
230/* else */
231 data[9] = 0x52; /* reg 8, 24MHz, no scale down */
Jean-Francois Moinea0306bf2009-01-08 16:29:38 -0300232/*jfm: from win trace*/
233 data[10] = 0x18;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300234
Jean-Francois Moinea0306bf2009-01-08 16:29:38 -0300235 err_code = reg_w(gspca_dev, 11);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300236 if (err_code < 0)
Jean-Francois Moine72ab97c2008-09-20 06:39:08 -0300237 return err_code;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300238
239 data[0] = 0x23; /* address */
240 data[1] = 0x09; /* reg 35, append frame header */
241
Jean-Francois Moinea0306bf2009-01-08 16:29:38 -0300242 err_code = reg_w(gspca_dev, 2);
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300243 if (err_code < 0)
Jean-Francois Moine72ab97c2008-09-20 06:39:08 -0300244 return err_code;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300245
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300246 data[0] = 0x3c; /* address */
247/* if (gspca_dev->width == 1280) */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300248/* data[1] = 200; * reg 60, pc-cam frame size
249 * (unit: 4KB) 800KB */
250/* else */
251 data[1] = 50; /* 50 reg 60, pc-cam frame size
252 * (unit: 4KB) 200KB */
Jean-Francois Moinea0306bf2009-01-08 16:29:38 -0300253 err_code = reg_w(gspca_dev, 2);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300254 if (err_code < 0)
Jean-Francois Moine72ab97c2008-09-20 06:39:08 -0300255 return err_code;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300256
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300257 /* auto dark-gain */
258 data[0] = 0x5e; /* address */
Jean-Francois Moinea0306bf2009-01-08 16:29:38 -0300259 data[1] = 0; /* reg 94, Y Gain (auto) */
260/*jfm: from win trace*/
Jean-Francois Moine253bae52009-02-28 08:09:24 -0300261 /* reg 0x5f/0x60 (LE) = saturation */
262 /* h (60): xxxx x100
263 * l (5f): xxxx x000 */
264 data[2] = sd->colors << 3;
265 data[3] = ((sd->colors >> 2) & 0xf8) | 0x04;
Jean-Francois Moinea0306bf2009-01-08 16:29:38 -0300266 data[4] = sd->brightness; /* reg 0x61 = brightness */
267 data[5] = 0x00;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300268
Jean-Francois Moinea0306bf2009-01-08 16:29:38 -0300269 err_code = reg_w(gspca_dev, 6);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300270 if (err_code < 0)
Jean-Francois Moine72ab97c2008-09-20 06:39:08 -0300271 return err_code;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300272
273 data[0] = 0x67;
Jean-Francois Moinea0306bf2009-01-08 16:29:38 -0300274/*jfm: from win trace*/
275 data[1] = sd->sharpness * 4 + 3;
276 data[2] = 0x14;
277 err_code = reg_w(gspca_dev, 3);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300278 if (err_code < 0)
Jean-Francois Moine72ab97c2008-09-20 06:39:08 -0300279 return err_code;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300280
Jean-Francois Moinea0306bf2009-01-08 16:29:38 -0300281 data[0] = 0x69;
282 data[1] = 0x2f;
283 data[2] = 0x28;
284 data[3] = 0x42;
285 err_code = reg_w(gspca_dev, 4);
286 if (err_code < 0)
287 return err_code;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300288
Jean-Francois Moinea0306bf2009-01-08 16:29:38 -0300289 data[0] = 0x63;
290 data[1] = 0x07;
291 err_code = reg_w(gspca_dev, 2);
292/*jfm: win trace - many writes here to reg 0x64*/
293 if (err_code < 0)
294 return err_code;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300295
Jean-Francois Moinea0306bf2009-01-08 16:29:38 -0300296 /* initialize the MI sensor */
297 for (i = 0; i < sizeof mi_data; i++)
298 mi_w(gspca_dev, i + 1, mi_data[i]);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300299
300 data[0] = 0x00;
301 data[1] = 0x4d; /* ISOC transfering enable... */
Jean-Francois Moinea0306bf2009-01-08 16:29:38 -0300302 reg_w(gspca_dev, 2);
303 return 0;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300304}
305
306static void sd_stopN(struct gspca_dev *gspca_dev)
307{
308 int result;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300309
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300310 gspca_dev->usb_buf[0] = 1;
311 gspca_dev->usb_buf[1] = 0;
Jean-Francois Moinea0306bf2009-01-08 16:29:38 -0300312 result = reg_w(gspca_dev, 2);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300313 if (result < 0)
314 PDEBUG(D_ERR, "Camera Stop failed");
315}
316
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300317static void sd_pkt_scan(struct gspca_dev *gspca_dev,
Jean-Francois Moine76dd2722009-11-13 09:21:03 -0300318 u8 *data, /* isoc packet */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300319 int len) /* iso packet length */
320{
Jean-Francois Moine71cb2762009-03-03 05:33:41 -0300321 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300322 int p;
323
324 if (len < 6) {
325/* gspca_dev->last_packet_type = DISCARD_PACKET; */
326 return;
327 }
328 for (p = 0; p < len - 6; p++) {
329 if (data[0 + p] == 0xff
330 && data[1 + p] == 0xff
331 && data[2 + p] == 0x00
332 && data[3 + p] == 0xff
333 && data[4 + p] == 0x96) {
334 if (data[5 + p] == 0x64
335 || data[5 + p] == 0x65
336 || data[5 + p] == 0x66
337 || data[5 + p] == 0x67) {
Jean-Francois Moinea0306bf2009-01-08 16:29:38 -0300338 PDEBUG(D_PACK, "sof offset: %d len: %d",
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300339 p, len);
Jean-Francois Moine76dd2722009-11-13 09:21:03 -0300340 gspca_frame_add(gspca_dev, LAST_PACKET,
341 data, p);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300342
343 /* put the JPEG header */
Jean-Francois Moine76dd2722009-11-13 09:21:03 -0300344 gspca_frame_add(gspca_dev, FIRST_PACKET,
Jean-Francois Moine71cb2762009-03-03 05:33:41 -0300345 sd->jpeg_hdr, JPEG_HDR_SZ);
Jean-Francois Moine0a32ef32009-01-08 16:30:58 -0300346 data += p + 16;
347 len -= p + 16;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300348 break;
349 }
350 }
351 }
Jean-Francois Moine76dd2722009-11-13 09:21:03 -0300352 gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300353}
354
Jean-Francois Moinea0306bf2009-01-08 16:29:38 -0300355static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
356{
357 struct sd *sd = (struct sd *) gspca_dev;
358
359 sd->brightness = val;
360 if (gspca_dev->streaming) {
361 gspca_dev->usb_buf[0] = 0x61;
362 gspca_dev->usb_buf[1] = val;
363 reg_w(gspca_dev, 2);
364 }
365 return 0;
366}
367
368static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
369{
370 struct sd *sd = (struct sd *) gspca_dev;
371
372 *val = sd->brightness;
373 return 0;
374}
375
376static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val)
377{
378 struct sd *sd = (struct sd *) gspca_dev;
379
380 sd->colors = val;
381 if (gspca_dev->streaming) {
Jean-Francois Moine253bae52009-02-28 08:09:24 -0300382
383 /* see sd_start */
Jean-Francois Moinea0306bf2009-01-08 16:29:38 -0300384 gspca_dev->usb_buf[0] = 0x5f;
Jean-Francois Moine253bae52009-02-28 08:09:24 -0300385 gspca_dev->usb_buf[1] = sd->colors << 3;
386 gspca_dev->usb_buf[2] = ((sd->colors >> 2) & 0xf8) | 0x04;
Jean-Francois Moinea0306bf2009-01-08 16:29:38 -0300387 reg_w(gspca_dev, 3);
388 }
389 return 0;
390}
391
392static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val)
393{
394 struct sd *sd = (struct sd *) gspca_dev;
395
396 *val = sd->colors;
397 return 0;
398}
399
400static int sd_setgamma(struct gspca_dev *gspca_dev, __s32 val)
401{
402 struct sd *sd = (struct sd *) gspca_dev;
403
404 sd->gamma = val;
405 if (gspca_dev->streaming) {
406 gspca_dev->usb_buf[0] = 0x06;
407 gspca_dev->usb_buf[1] = val * 0x40;
408 reg_w(gspca_dev, 2);
409 }
410 return 0;
411}
412
413static int sd_getgamma(struct gspca_dev *gspca_dev, __s32 *val)
414{
415 struct sd *sd = (struct sd *) gspca_dev;
416
417 *val = sd->gamma;
418 return 0;
419}
420
421static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val)
422{
423 struct sd *sd = (struct sd *) gspca_dev;
424
425 sd->sharpness = val;
426 if (gspca_dev->streaming) {
427 gspca_dev->usb_buf[0] = 0x67;
428 gspca_dev->usb_buf[1] = val * 4 + 3;
429 reg_w(gspca_dev, 2);
430 }
431 return 0;
432}
433
434static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val)
435{
436 struct sd *sd = (struct sd *) gspca_dev;
437
438 *val = sd->sharpness;
439 return 0;
440}
441
Jean-Francois Moine77ac0ba2009-03-02 06:40:52 -0300442static int sd_set_jcomp(struct gspca_dev *gspca_dev,
443 struct v4l2_jpegcompression *jcomp)
444{
445 struct sd *sd = (struct sd *) gspca_dev;
446
447 if (jcomp->quality < QUALITY_MIN)
448 sd->quality = QUALITY_MIN;
449 else if (jcomp->quality > QUALITY_MAX)
450 sd->quality = QUALITY_MAX;
451 else
452 sd->quality = jcomp->quality;
453 if (gspca_dev->streaming)
454 jpeg_set_qual(sd->jpeg_hdr, sd->quality);
455 return 0;
456}
457
458static int sd_get_jcomp(struct gspca_dev *gspca_dev,
459 struct v4l2_jpegcompression *jcomp)
460{
461 struct sd *sd = (struct sd *) gspca_dev;
462
463 memset(jcomp, 0, sizeof *jcomp);
464 jcomp->quality = sd->quality;
465 jcomp->jpeg_markers = V4L2_JPEG_MARKER_DHT
466 | V4L2_JPEG_MARKER_DQT;
467 return 0;
468}
469
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300470/* sub-driver description */
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -0300471static const struct sd_desc sd_desc = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300472 .name = MODULE_NAME,
473 .ctrls = sd_ctrls,
474 .nctrls = ARRAY_SIZE(sd_ctrls),
475 .config = sd_config,
Jean-Francois Moine012d6b02008-09-03 17:12:16 -0300476 .init = sd_init,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300477 .start = sd_start,
478 .stopN = sd_stopN,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300479 .pkt_scan = sd_pkt_scan,
Jean-Francois Moine77ac0ba2009-03-02 06:40:52 -0300480 .get_jcomp = sd_get_jcomp,
481 .set_jcomp = sd_set_jcomp,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300482};
483
484/* -- module initialisation -- */
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -0300485static const __devinitdata struct usb_device_id device_table[] = {
Jean-Francois Moine9d64fdb2008-07-25 08:53:03 -0300486 {USB_DEVICE(0x093a, 0x050f)},
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300487 {}
488};
489MODULE_DEVICE_TABLE(usb, device_table);
490
491/* -- device connect -- */
492static int sd_probe(struct usb_interface *intf,
493 const struct usb_device_id *id)
494{
495 return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
496 THIS_MODULE);
497}
498
499static struct usb_driver sd_driver = {
500 .name = MODULE_NAME,
501 .id_table = device_table,
502 .probe = sd_probe,
503 .disconnect = gspca_disconnect,
Jean-Francois Moine6a709742008-09-03 16:48:10 -0300504#ifdef CONFIG_PM
505 .suspend = gspca_suspend,
506 .resume = gspca_resume,
507#endif
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300508};
509
510/* -- module insert / remove -- */
511static int __init sd_mod_init(void)
512{
Alexey Klimovf69e9522009-01-01 13:02:07 -0300513 int ret;
Jean-Francois Moinea0306bf2009-01-08 16:29:38 -0300514
Alexey Klimovf69e9522009-01-01 13:02:07 -0300515 ret = usb_register(&sd_driver);
516 if (ret < 0)
Alexey Klimove6b14842009-01-01 13:04:58 -0300517 return ret;
Jean-Francois Moine10b0e962008-07-22 05:35:10 -0300518 PDEBUG(D_PROBE, "registered");
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300519 return 0;
520}
521static void __exit sd_mod_exit(void)
522{
523 usb_deregister(&sd_driver);
524 PDEBUG(D_PROBE, "deregistered");
525}
526
527module_init(sd_mod_init);
528module_exit(sd_mod_exit);