~ubuntu-branches/ubuntu/saucy/linux-ti-omap4/saucy-proposed

« back to all changes in this revision

Viewing changes to drivers/media/video/gspca/pac7311.c

  • Committer: Package Import Robot
  • Author(s): Paolo Pisati, Paolo Pisati, Stefan Bader, Upstream Kernel Changes
  • Date: 2012-08-15 17:17:43 UTC
  • Revision ID: package-import@ubuntu.com-20120815171743-h5wnuf51xe7pvdid
Tags: 3.5.0-207.13
[ Paolo Pisati ]

* Start new release

[ Stefan Bader ]

* (config) Enable getabis to use local package copies

[ Upstream Kernel Changes ]

* fixup: gargabe collect iva_seq[0|1] init
* [Config] enable all SND_OMAP_SOC_*s
* fixup: cm2xxx_3xxx.o is needed for omap2_cm_read|write_reg
* fixup: add some snd_soc_dai* helper functions
* fixup: s/snd_soc_dpcm_params/snd_soc_dpcm/g
* fixup: typo, no_host_mode and useless SDP4430 init
* fixup: enable again aess hwmod

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 */
21
21
 
22
22
/* Some documentation about various registers as determined by trial and error.
23
 
   When the register addresses differ between the 7202 and the 7311 the 2
24
 
   different addresses are written as 7302addr/7311addr, when one of the 2
25
 
   addresses is a - sign that register description is not valid for the
26
 
   matching IC.
27
 
 
28
 
   Register page 1:
29
 
 
30
 
   Address      Description
31
 
   -/0x08       Unknown compressor related, must always be 8 except when not
32
 
                in 640x480 resolution and page 4 reg 2 <= 3 then set it to 9 !
33
 
   -/0x1b       Auto white balance related, bit 0 is AWB enable (inverted)
34
 
                bits 345 seem to toggle per color gains on/off (inverted)
35
 
   0x78         Global control, bit 6 controls the LED (inverted)
36
 
   -/0x80       JPEG compression ratio ? Best not touched
37
 
 
38
 
   Register page 3/4:
39
 
 
40
 
   Address      Description
41
 
   0x02         Clock divider 2-63, fps =~ 60 / val. Must be a multiple of 3 on
42
 
                the 7302, so one of 3, 6, 9, ..., except when between 6 and 12?
43
 
   -/0x0f       Master gain 1-245, low value = high gain
44
 
   0x10/-       Master gain 0-31
45
 
   -/0x10       Another gain 0-15, limited influence (1-2x gain I guess)
46
 
   0x21         Bitfield: 0-1 unused, 2-3 vflip/hflip, 4-5 unknown, 6-7 unused
47
 
   -/0x27       Seems to toggle various gains on / off, Setting bit 7 seems to
48
 
                completely disable the analog amplification block. Set to 0x68
49
 
                for max gain, 0x14 for minimal gain.
50
 
*/
 
23
 *
 
24
 * Register page 1:
 
25
 *
 
26
 * Address      Description
 
27
 * 0x08         Unknown compressor related, must always be 8 except when not
 
28
 *              in 640x480 resolution and page 4 reg 2 <= 3 then set it to 9 !
 
29
 * 0x1b         Auto white balance related, bit 0 is AWB enable (inverted)
 
30
 *              bits 345 seem to toggle per color gains on/off (inverted)
 
31
 * 0x78         Global control, bit 6 controls the LED (inverted)
 
32
 * 0x80         Compression balance, interesting settings:
 
33
 *              0x01 Use this to allow the camera to switch to higher compr.
 
34
 *                   on the fly. Needed to stay within bandwidth @ 640x480@30
 
35
 *              0x1c From usb captures under Windows for 640x480
 
36
 *              0x2a Values >= this switch the camera to a lower compression,
 
37
 *                   using the same table for both luminance and chrominance.
 
38
 *                   This gives a sharper picture. Usable only at 640x480@ <
 
39
 *                   15 fps or 320x240 / 160x120. Note currently the driver
 
40
 *                   does not use this as the quality gain is small and the
 
41
 *                   generated JPG-s are only understood by v4l-utils >= 0.8.9
 
42
 *              0x3f From usb captures under Windows for 320x240
 
43
 *              0x69 From usb captures under Windows for 160x120
 
44
 *
 
45
 * Register page 4:
 
46
 *
 
47
 * Address      Description
 
48
 * 0x02         Clock divider 2-63, fps =~ 60 / val. Must be a multiple of 3 on
 
49
 *              the 7302, so one of 3, 6, 9, ..., except when between 6 and 12?
 
50
 * 0x0f         Master gain 1-245, low value = high gain
 
51
 * 0x10         Another gain 0-15, limited influence (1-2x gain I guess)
 
52
 * 0x21         Bitfield: 0-1 unused, 2-3 vflip/hflip, 4-5 unknown, 6-7 unused
 
53
 *              Note setting vflip disabled leads to a much lower image quality,
 
54
 *              so we always vflip, and tell userspace to flip it back
 
55
 * 0x27         Seems to toggle various gains on / off, Setting bit 7 seems to
 
56
 *              completely disable the analog amplification block. Set to 0x68
 
57
 *              for max gain, 0x14 for minimal gain.
 
58
 */
51
59
 
52
60
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
53
61
 
55
63
 
56
64
#include <linux/input.h>
57
65
#include "gspca.h"
 
66
/* Include pac common sof detection functions */
 
67
#include "pac_common.h"
 
68
 
 
69
#define PAC7311_GAIN_DEFAULT     122
 
70
#define PAC7311_EXPOSURE_DEFAULT   3 /* 20 fps, avoid using high compr. */
58
71
 
59
72
MODULE_AUTHOR("Thomas Kaiser thomas@kaiser-linux.li");
60
73
MODULE_DESCRIPTION("Pixart PAC7311");
61
74
MODULE_LICENSE("GPL");
62
75
 
63
 
/* specific webcam descriptor for pac7311 */
64
76
struct sd {
65
77
        struct gspca_dev gspca_dev;             /* !! must be the first item */
66
78
 
67
 
        unsigned char contrast;
68
 
        unsigned char gain;
69
 
        unsigned char exposure;
70
 
        unsigned char autogain;
71
 
        __u8 hflip;
72
 
        __u8 vflip;
 
79
        struct v4l2_ctrl *contrast;
 
80
        struct v4l2_ctrl *hflip;
73
81
 
74
82
        u8 sof_read;
75
83
        u8 autogain_ignore_frames;
77
85
        atomic_t avg_lum;
78
86
};
79
87
 
80
 
/* V4L2 controls supported by the driver */
81
 
static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);
82
 
static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
83
 
static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val);
84
 
static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val);
85
 
static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val);
86
 
static int sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val);
87
 
static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val);
88
 
static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val);
89
 
static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val);
90
 
static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val);
91
 
static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val);
92
 
static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val);
93
 
 
94
 
static const struct ctrl sd_ctrls[] = {
95
 
/* This control is for both the 7302 and the 7311 */
96
 
        {
97
 
            {
98
 
                .id      = V4L2_CID_CONTRAST,
99
 
                .type    = V4L2_CTRL_TYPE_INTEGER,
100
 
                .name    = "Contrast",
101
 
                .minimum = 0,
102
 
#define CONTRAST_MAX 255
103
 
                .maximum = CONTRAST_MAX,
104
 
                .step    = 1,
105
 
#define CONTRAST_DEF 127
106
 
                .default_value = CONTRAST_DEF,
107
 
            },
108
 
            .set = sd_setcontrast,
109
 
            .get = sd_getcontrast,
110
 
        },
111
 
/* All controls below are for both the 7302 and the 7311 */
112
 
        {
113
 
            {
114
 
                .id      = V4L2_CID_GAIN,
115
 
                .type    = V4L2_CTRL_TYPE_INTEGER,
116
 
                .name    = "Gain",
117
 
                .minimum = 0,
118
 
#define GAIN_MAX 255
119
 
                .maximum = GAIN_MAX,
120
 
                .step    = 1,
121
 
#define GAIN_DEF 127
122
 
#define GAIN_KNEE 255 /* Gain seems to cause little noise on the pac73xx */
123
 
                .default_value = GAIN_DEF,
124
 
            },
125
 
            .set = sd_setgain,
126
 
            .get = sd_getgain,
127
 
        },
128
 
        {
129
 
            {
130
 
                .id      = V4L2_CID_EXPOSURE,
131
 
                .type    = V4L2_CTRL_TYPE_INTEGER,
132
 
                .name    = "Exposure",
133
 
                .minimum = 0,
134
 
#define EXPOSURE_MAX 255
135
 
                .maximum = EXPOSURE_MAX,
136
 
                .step    = 1,
137
 
#define EXPOSURE_DEF  16 /*  32 ms / 30 fps */
138
 
#define EXPOSURE_KNEE 50 /* 100 ms / 10 fps */
139
 
                .default_value = EXPOSURE_DEF,
140
 
            },
141
 
            .set = sd_setexposure,
142
 
            .get = sd_getexposure,
143
 
        },
144
 
        {
145
 
            {
146
 
                .id      = V4L2_CID_AUTOGAIN,
147
 
                .type    = V4L2_CTRL_TYPE_BOOLEAN,
148
 
                .name    = "Auto Gain",
149
 
                .minimum = 0,
150
 
                .maximum = 1,
151
 
                .step    = 1,
152
 
#define AUTOGAIN_DEF 1
153
 
                .default_value = AUTOGAIN_DEF,
154
 
            },
155
 
            .set = sd_setautogain,
156
 
            .get = sd_getautogain,
157
 
        },
158
 
        {
159
 
            {
160
 
                .id      = V4L2_CID_HFLIP,
161
 
                .type    = V4L2_CTRL_TYPE_BOOLEAN,
162
 
                .name    = "Mirror",
163
 
                .minimum = 0,
164
 
                .maximum = 1,
165
 
                .step    = 1,
166
 
#define HFLIP_DEF 0
167
 
                .default_value = HFLIP_DEF,
168
 
            },
169
 
            .set = sd_sethflip,
170
 
            .get = sd_gethflip,
171
 
        },
172
 
        {
173
 
            {
174
 
                .id      = V4L2_CID_VFLIP,
175
 
                .type    = V4L2_CTRL_TYPE_BOOLEAN,
176
 
                .name    = "Vflip",
177
 
                .minimum = 0,
178
 
                .maximum = 1,
179
 
                .step    = 1,
180
 
#define VFLIP_DEF 0
181
 
                .default_value = VFLIP_DEF,
182
 
            },
183
 
            .set = sd_setvflip,
184
 
            .get = sd_getvflip,
185
 
        },
186
 
};
187
 
 
188
88
static const struct v4l2_pix_format vga_mode[] = {
189
89
        {160, 120, V4L2_PIX_FMT_PJPG, V4L2_FIELD_NONE,
190
90
                .bytesperline = 160,
206
106
#define LOAD_PAGE4              254
207
107
#define END_OF_SEQUENCE         0
208
108
 
209
 
/* pac 7311 */
210
109
static const __u8 init_7311[] = {
 
110
        0xff, 0x01,
211
111
        0x78, 0x40,     /* Bit_0=start stream, Bit_6=LED */
212
112
        0x78, 0x40,     /* Bit_0=start stream, Bit_6=LED */
213
113
        0x78, 0x44,     /* Bit_0=start stream, Bit_6=LED */
387
287
static int sd_config(struct gspca_dev *gspca_dev,
388
288
                        const struct usb_device_id *id)
389
289
{
390
 
        struct sd *sd = (struct sd *) gspca_dev;
391
 
        struct cam *cam;
392
 
 
393
 
        cam = &gspca_dev->cam;
394
 
 
395
 
        PDEBUG(D_CONF, "Find Sensor PAC7311");
 
290
        struct cam *cam = &gspca_dev->cam;
 
291
 
396
292
        cam->cam_mode = vga_mode;
397
293
        cam->nmodes = ARRAY_SIZE(vga_mode);
 
294
        cam->input_flags = V4L2_IN_ST_VFLIP;
398
295
 
399
 
        sd->contrast = CONTRAST_DEF;
400
 
        sd->gain = GAIN_DEF;
401
 
        sd->exposure = EXPOSURE_DEF;
402
 
        sd->autogain = AUTOGAIN_DEF;
403
 
        sd->hflip = HFLIP_DEF;
404
 
        sd->vflip = VFLIP_DEF;
405
296
        return 0;
406
297
}
407
298
 
408
 
/* This function is used by pac7311 only */
409
 
static void setcontrast(struct gspca_dev *gspca_dev)
 
299
static void setcontrast(struct gspca_dev *gspca_dev, s32 val)
410
300
{
411
 
        struct sd *sd = (struct sd *) gspca_dev;
412
 
 
413
301
        reg_w(gspca_dev, 0xff, 0x04);
414
 
        reg_w(gspca_dev, 0x10, sd->contrast >> 4);
 
302
        reg_w(gspca_dev, 0x10, val);
415
303
        /* load registers to sensor (Bit 0, auto clear) */
416
304
        reg_w(gspca_dev, 0x11, 0x01);
417
305
}
418
306
 
419
 
static void setgain(struct gspca_dev *gspca_dev)
 
307
static void setgain(struct gspca_dev *gspca_dev, s32 val)
420
308
{
421
 
        struct sd *sd = (struct sd *) gspca_dev;
422
 
        int gain = GAIN_MAX - sd->gain;
423
 
 
424
 
        if (gain < 1)
425
 
                gain = 1;
426
 
        else if (gain > 245)
427
 
                gain = 245;
428
309
        reg_w(gspca_dev, 0xff, 0x04);                   /* page 4 */
429
310
        reg_w(gspca_dev, 0x0e, 0x00);
430
 
        reg_w(gspca_dev, 0x0f, gain);
 
311
        reg_w(gspca_dev, 0x0f, gspca_dev->gain->maximum - val + 1);
431
312
 
432
313
        /* load registers to sensor (Bit 0, auto clear) */
433
314
        reg_w(gspca_dev, 0x11, 0x01);
434
315
}
435
316
 
436
 
static void setexposure(struct gspca_dev *gspca_dev)
 
317
static void setexposure(struct gspca_dev *gspca_dev, s32 val)
437
318
{
438
 
        struct sd *sd = (struct sd *) gspca_dev;
439
 
        __u8 reg;
440
 
 
441
 
        /* register 2 of frame 3/4 contains the clock divider configuring the
442
 
           no fps according to the formula: 60 / reg. sd->exposure is the
443
 
           desired exposure time in ms. */
444
 
        reg = 120 * sd->exposure / 1000;
445
 
        if (reg < 2)
446
 
                reg = 2;
447
 
        else if (reg > 63)
448
 
                reg = 63;
449
 
 
450
319
        reg_w(gspca_dev, 0xff, 0x04);                   /* page 4 */
451
 
        reg_w(gspca_dev, 0x02, reg);
452
 
 
453
 
        /* Page 1 register 8 must always be 0x08 except when not in
454
 
           640x480 mode and Page3/4 reg 2 <= 3 then it must be 9 */
 
320
        reg_w(gspca_dev, 0x02, val);
 
321
 
 
322
        /* load registers to sensor (Bit 0, auto clear) */
 
323
        reg_w(gspca_dev, 0x11, 0x01);
 
324
 
 
325
        /*
 
326
         * Page 1 register 8 must always be 0x08 except when not in
 
327
         *  640x480 mode and page 4 reg 2 <= 3 then it must be 9
 
328
         */
455
329
        reg_w(gspca_dev, 0xff, 0x01);
456
 
        if (gspca_dev->cam.cam_mode[(int)gspca_dev->curr_mode].priv &&
457
 
                        reg <= 3) {
 
330
        if (gspca_dev->width != 640 && val <= 3)
458
331
                reg_w(gspca_dev, 0x08, 0x09);
459
 
        } else {
 
332
        else
460
333
                reg_w(gspca_dev, 0x08, 0x08);
461
 
        }
 
334
 
 
335
        /*
 
336
         * Page1 register 80 sets the compression balance, normally we
 
337
         * want / use 0x1c, but for 640x480@30fps we must allow the
 
338
         * camera to use higher compression or we may run out of
 
339
         * bandwidth.
 
340
         */
 
341
        if (gspca_dev->width == 640 && val == 2)
 
342
                reg_w(gspca_dev, 0x80, 0x01);
 
343
        else
 
344
                reg_w(gspca_dev, 0x80, 0x1c);
462
345
 
463
346
        /* load registers to sensor (Bit 0, auto clear) */
464
347
        reg_w(gspca_dev, 0x11, 0x01);
465
348
}
466
349
 
467
 
static void sethvflip(struct gspca_dev *gspca_dev)
 
350
static void sethvflip(struct gspca_dev *gspca_dev, s32 hflip, s32 vflip)
468
351
{
469
 
        struct sd *sd = (struct sd *) gspca_dev;
470
352
        __u8 data;
471
353
 
472
354
        reg_w(gspca_dev, 0xff, 0x04);                   /* page 4 */
473
 
        data = (sd->hflip ? 0x04 : 0x00) | (sd->vflip ? 0x08 : 0x00);
 
355
        data = (hflip ? 0x04 : 0x00) |
 
356
               (vflip ? 0x08 : 0x00);
474
357
        reg_w(gspca_dev, 0x21, data);
475
358
 
476
359
        /* load registers to sensor (Bit 0, auto clear) */
484
367
        return gspca_dev->usb_err;
485
368
}
486
369
 
 
370
static int sd_s_ctrl(struct v4l2_ctrl *ctrl)
 
371
{
 
372
        struct gspca_dev *gspca_dev =
 
373
                container_of(ctrl->handler, struct gspca_dev, ctrl_handler);
 
374
        struct sd *sd = (struct sd *)gspca_dev;
 
375
 
 
376
        gspca_dev->usb_err = 0;
 
377
 
 
378
        if (ctrl->id == V4L2_CID_AUTOGAIN && ctrl->is_new && ctrl->val) {
 
379
                /* when switching to autogain set defaults to make sure
 
380
                   we are on a valid point of the autogain gain /
 
381
                   exposure knee graph, and give this change time to
 
382
                   take effect before doing autogain. */
 
383
                gspca_dev->exposure->val    = PAC7311_EXPOSURE_DEFAULT;
 
384
                gspca_dev->gain->val        = PAC7311_GAIN_DEFAULT;
 
385
                sd->autogain_ignore_frames  = PAC_AUTOGAIN_IGNORE_FRAMES;
 
386
        }
 
387
 
 
388
        if (!gspca_dev->streaming)
 
389
                return 0;
 
390
 
 
391
        switch (ctrl->id) {
 
392
        case V4L2_CID_CONTRAST:
 
393
                setcontrast(gspca_dev, ctrl->val);
 
394
                break;
 
395
        case V4L2_CID_AUTOGAIN:
 
396
                if (gspca_dev->exposure->is_new || (ctrl->is_new && ctrl->val))
 
397
                        setexposure(gspca_dev, gspca_dev->exposure->val);
 
398
                if (gspca_dev->gain->is_new || (ctrl->is_new && ctrl->val))
 
399
                        setgain(gspca_dev, gspca_dev->gain->val);
 
400
                break;
 
401
        case V4L2_CID_HFLIP:
 
402
                sethvflip(gspca_dev, sd->hflip->val, 1);
 
403
                break;
 
404
        default:
 
405
                return -EINVAL;
 
406
        }
 
407
        return gspca_dev->usb_err;
 
408
}
 
409
 
 
410
static const struct v4l2_ctrl_ops sd_ctrl_ops = {
 
411
        .s_ctrl = sd_s_ctrl,
 
412
};
 
413
 
 
414
/* this function is called at probe time */
 
415
static int sd_init_controls(struct gspca_dev *gspca_dev)
 
416
{
 
417
        struct sd *sd = (struct sd *) gspca_dev;
 
418
        struct v4l2_ctrl_handler *hdl = &gspca_dev->ctrl_handler;
 
419
 
 
420
        gspca_dev->vdev.ctrl_handler = hdl;
 
421
        v4l2_ctrl_handler_init(hdl, 5);
 
422
 
 
423
        sd->contrast = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
 
424
                                        V4L2_CID_CONTRAST, 0, 15, 1, 7);
 
425
        gspca_dev->autogain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
 
426
                                        V4L2_CID_AUTOGAIN, 0, 1, 1, 1);
 
427
        gspca_dev->exposure = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
 
428
                                        V4L2_CID_EXPOSURE, 2, 63, 1,
 
429
                                        PAC7311_EXPOSURE_DEFAULT);
 
430
        gspca_dev->gain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
 
431
                                        V4L2_CID_GAIN, 0, 244, 1,
 
432
                                        PAC7311_GAIN_DEFAULT);
 
433
        sd->hflip = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
 
434
                V4L2_CID_HFLIP, 0, 1, 1, 0);
 
435
 
 
436
        if (hdl->error) {
 
437
                pr_err("Could not initialize controls\n");
 
438
                return hdl->error;
 
439
        }
 
440
 
 
441
        v4l2_ctrl_auto_cluster(3, &gspca_dev->autogain, 0, false);
 
442
        return 0;
 
443
}
 
444
 
 
445
/* -- start the camera -- */
487
446
static int sd_start(struct gspca_dev *gspca_dev)
488
447
{
489
448
        struct sd *sd = (struct sd *) gspca_dev;
492
451
 
493
452
        reg_w_var(gspca_dev, start_7311,
494
453
                page4_7311, sizeof(page4_7311));
495
 
        setcontrast(gspca_dev);
496
 
        setgain(gspca_dev);
497
 
        setexposure(gspca_dev);
498
 
        sethvflip(gspca_dev);
 
454
        setcontrast(gspca_dev, v4l2_ctrl_g_ctrl(sd->contrast));
 
455
        setgain(gspca_dev, v4l2_ctrl_g_ctrl(gspca_dev->gain));
 
456
        setexposure(gspca_dev, v4l2_ctrl_g_ctrl(gspca_dev->exposure));
 
457
        sethvflip(gspca_dev, v4l2_ctrl_g_ctrl(sd->hflip), 1);
499
458
 
500
459
        /* set correct resolution */
501
460
        switch (gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv) {
502
 
        case 2:                                 /* 160x120 pac7311 */
 
461
        case 2:                                 /* 160x120 */
503
462
                reg_w(gspca_dev, 0xff, 0x01);
504
463
                reg_w(gspca_dev, 0x17, 0x20);
505
464
                reg_w(gspca_dev, 0x87, 0x10);
506
465
                break;
507
 
        case 1:                                 /* 320x240 pac7311 */
 
466
        case 1:                                 /* 320x240 */
508
467
                reg_w(gspca_dev, 0xff, 0x01);
509
468
                reg_w(gspca_dev, 0x17, 0x30);
510
469
                reg_w(gspca_dev, 0x87, 0x11);
541
500
        reg_w(gspca_dev, 0x78, 0x44); /* Bit_0=start stream, Bit_6=LED */
542
501
}
543
502
 
544
 
/* called on streamoff with alt 0 and on disconnect for 7311 */
545
 
static void sd_stop0(struct gspca_dev *gspca_dev)
546
 
{
547
 
}
548
 
 
549
 
/* Include pac common sof detection functions */
550
 
#include "pac_common.h"
551
 
 
552
503
static void do_autogain(struct gspca_dev *gspca_dev)
553
504
{
554
505
        struct sd *sd = (struct sd *) gspca_dev;
558
509
        if (avg_lum == -1)
559
510
                return;
560
511
 
561
 
        desired_lum = 200;
 
512
        desired_lum = 170;
562
513
        deadzone = 20;
563
514
 
564
515
        if (sd->autogain_ignore_frames > 0)
565
516
                sd->autogain_ignore_frames--;
566
 
        else if (gspca_auto_gain_n_exposure(gspca_dev, avg_lum, desired_lum,
567
 
                        deadzone, GAIN_KNEE, EXPOSURE_KNEE))
 
517
        else if (gspca_coarse_grained_expo_autogain(gspca_dev, avg_lum,
 
518
                                                    desired_lum, deadzone))
568
519
                sd->autogain_ignore_frames = PAC_AUTOGAIN_IGNORE_FRAMES;
569
520
}
570
521
 
628
579
        if (sof) {
629
580
                int n, lum_offset, footer_length;
630
581
 
631
 
                /* 6 bytes after the FF D9 EOF marker a number of lumination
632
 
                   bytes are send corresponding to different parts of the
633
 
                   image, the 14th and 15th byte after the EOF seem to
634
 
                   correspond to the center of the image */
 
582
                /*
 
583
                 * 6 bytes after the FF D9 EOF marker a number of lumination
 
584
                 * bytes are send corresponding to different parts of the
 
585
                 * image, the 14th and 15th byte after the EOF seem to
 
586
                 * correspond to the center of the image.
 
587
                 */
635
588
                lum_offset = 24 + sizeof pac_sof_marker;
636
589
                footer_length = 26;
637
590
 
668
621
        gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
669
622
}
670
623
 
671
 
static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
672
 
{
673
 
        struct sd *sd = (struct sd *) gspca_dev;
674
 
 
675
 
        sd->contrast = val;
676
 
        if (gspca_dev->streaming)
677
 
                setcontrast(gspca_dev);
678
 
        return gspca_dev->usb_err;
679
 
}
680
 
 
681
 
static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
682
 
{
683
 
        struct sd *sd = (struct sd *) gspca_dev;
684
 
 
685
 
        *val = sd->contrast;
686
 
        return 0;
687
 
}
688
 
 
689
 
static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val)
690
 
{
691
 
        struct sd *sd = (struct sd *) gspca_dev;
692
 
 
693
 
        sd->gain = val;
694
 
        if (gspca_dev->streaming)
695
 
                setgain(gspca_dev);
696
 
        return gspca_dev->usb_err;
697
 
}
698
 
 
699
 
static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val)
700
 
{
701
 
        struct sd *sd = (struct sd *) gspca_dev;
702
 
 
703
 
        *val = sd->gain;
704
 
        return 0;
705
 
}
706
 
 
707
 
static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val)
708
 
{
709
 
        struct sd *sd = (struct sd *) gspca_dev;
710
 
 
711
 
        sd->exposure = val;
712
 
        if (gspca_dev->streaming)
713
 
                setexposure(gspca_dev);
714
 
        return gspca_dev->usb_err;
715
 
}
716
 
 
717
 
static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val)
718
 
{
719
 
        struct sd *sd = (struct sd *) gspca_dev;
720
 
 
721
 
        *val = sd->exposure;
722
 
        return 0;
723
 
}
724
 
 
725
 
static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val)
726
 
{
727
 
        struct sd *sd = (struct sd *) gspca_dev;
728
 
 
729
 
        sd->autogain = val;
730
 
        /* when switching to autogain set defaults to make sure
731
 
           we are on a valid point of the autogain gain /
732
 
           exposure knee graph, and give this change time to
733
 
           take effect before doing autogain. */
734
 
        if (sd->autogain) {
735
 
                sd->exposure = EXPOSURE_DEF;
736
 
                sd->gain = GAIN_DEF;
737
 
                if (gspca_dev->streaming) {
738
 
                        sd->autogain_ignore_frames =
739
 
                                PAC_AUTOGAIN_IGNORE_FRAMES;
740
 
                        setexposure(gspca_dev);
741
 
                        setgain(gspca_dev);
742
 
                }
743
 
        }
744
 
 
745
 
        return gspca_dev->usb_err;
746
 
}
747
 
 
748
 
static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val)
749
 
{
750
 
        struct sd *sd = (struct sd *) gspca_dev;
751
 
 
752
 
        *val = sd->autogain;
753
 
        return 0;
754
 
}
755
 
 
756
 
static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val)
757
 
{
758
 
        struct sd *sd = (struct sd *) gspca_dev;
759
 
 
760
 
        sd->hflip = val;
761
 
        if (gspca_dev->streaming)
762
 
                sethvflip(gspca_dev);
763
 
        return gspca_dev->usb_err;
764
 
}
765
 
 
766
 
static int sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val)
767
 
{
768
 
        struct sd *sd = (struct sd *) gspca_dev;
769
 
 
770
 
        *val = sd->hflip;
771
 
        return 0;
772
 
}
773
 
 
774
 
static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val)
775
 
{
776
 
        struct sd *sd = (struct sd *) gspca_dev;
777
 
 
778
 
        sd->vflip = val;
779
 
        if (gspca_dev->streaming)
780
 
                sethvflip(gspca_dev);
781
 
        return gspca_dev->usb_err;
782
 
}
783
 
 
784
 
static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val)
785
 
{
786
 
        struct sd *sd = (struct sd *) gspca_dev;
787
 
 
788
 
        *val = sd->vflip;
789
 
        return 0;
790
 
}
791
 
 
792
624
#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
793
625
static int sd_int_pkt_scan(struct gspca_dev *gspca_dev,
794
626
                        u8 *data,               /* interrupt packet data */
820
652
}
821
653
#endif
822
654
 
823
 
/* sub-driver description for pac7311 */
824
655
static const struct sd_desc sd_desc = {
825
656
        .name = MODULE_NAME,
826
 
        .ctrls = sd_ctrls,
827
 
        .nctrls = ARRAY_SIZE(sd_ctrls),
828
657
        .config = sd_config,
829
658
        .init = sd_init,
 
659
        .init_controls = sd_init_controls,
830
660
        .start = sd_start,
831
661
        .stopN = sd_stopN,
832
 
        .stop0 = sd_stop0,
833
662
        .pkt_scan = sd_pkt_scan,
834
663
        .dq_callback = do_autogain,
835
664
#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)