Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /* Subdriver for the GL860 chip with the OV2640 sensor
0003  * Author Olivier LORIN, from Malmostoso's logs
0004  */
0005 
0006 /* Sensor : OV2640 */
0007 
0008 #include "gl860.h"
0009 
0010 static u8 dat_init1[] = "\x00\x41\x07\x6a\x06\x61\x0d\x6a" "\x10\x10\xc1\x01";
0011 
0012 static u8 c61[] = {0x61}; /* expected */
0013 static u8 c51[] = {0x51}; /* expected */
0014 static u8 c50[] = {0x50}; /* expected */
0015 static u8 c28[] = {0x28}; /* expected */
0016 static u8 ca8[] = {0xa8}; /* expected */
0017 
0018 static u8 dat_post[] =
0019     "\x00\x41\x07\x6a\x06\xef\x0d\x6a" "\x10\x10\xc1\x01";
0020 
0021 static u8 dat_640[]  = "\xd0\x01\xd1\x08\xd2\xe0\xd3\x02\xd4\x10\xd5\x81";
0022 static u8 dat_800[]  = "\xd0\x01\xd1\x10\xd2\x58\xd3\x02\xd4\x18\xd5\x21";
0023 static u8 dat_1280[] = "\xd0\x01\xd1\x18\xd2\xc0\xd3\x02\xd4\x28\xd5\x01";
0024 static u8 dat_1600[] = "\xd0\x01\xd1\x20\xd2\xb0\xd3\x02\xd4\x30\xd5\x41";
0025 
0026 static struct validx tbl_init_at_startup[] = {
0027     {0x0000, 0x0000}, {0x0010, 0x0010}, {0x0008, 0x00c0}, {0x0001, 0x00c1},
0028     {0x0001, 0x00c2}, {0x0020, 0x0006}, {0x006a, 0x000d},
0029     {0x0050, 0x0000}, {0x0041, 0x0000}, {0x006a, 0x0007}, {0x0061, 0x0006},
0030     {0x006a, 0x000d}, {0x0000, 0x00c0}, {0x0010, 0x0010}, {0x0001, 0x00c1},
0031     {0x0041, 0x00c2}, {0x0004, 0x00d8}, {0x0012, 0x0004}, {0x0000, 0x0058},
0032     {0x0041, 0x0000}, {0x0061, 0x0000},
0033 };
0034 
0035 static struct validx tbl_common[] = {
0036     {0x6000, 0x00ff}, {0x60ff, 0x002c}, {0x60df, 0x002e}, {0x6001, 0x00ff},
0037     {0x6080, 0x0012}, {0x6000, 0x0000}, {0x6000, 0x0045}, {0x6000, 0x0010},
0038     {0x6035, 0x003c}, {0x6000, 0x0011}, {0x6028, 0x0004}, {0x60e5, 0x0013},
0039     {0x6088, 0x0014}, {0x600c, 0x002c}, {0x6078, 0x0033}, {0x60f7, 0x003b},
0040     {0x6000, 0x003e}, {0x6011, 0x0043}, {0x6010, 0x0016}, {0x6082, 0x0039},
0041     {0x6088, 0x0035}, {0x600a, 0x0022}, {0x6040, 0x0037}, {0x6000, 0x0023},
0042     {0x60a0, 0x0034}, {0x601a, 0x0036}, {0x6002, 0x0006}, {0x60c0, 0x0007},
0043     {0x60b7, 0x000d}, {0x6001, 0x000e}, {0x6000, 0x004c}, {0x6081, 0x004a},
0044     {0x6099, 0x0021}, {0x6002, 0x0009}, {0x603e, 0x0024}, {0x6034, 0x0025},
0045     {0x6081, 0x0026}, {0x6000, 0x0000}, {0x6000, 0x0045}, {0x6000, 0x0010},
0046     {0x6000, 0x005c}, {0x6000, 0x0063}, {0x6000, 0x007c}, {0x6070, 0x0061},
0047     {0x6080, 0x0062}, {0x6080, 0x0020}, {0x6030, 0x0028}, {0x6000, 0x006c},
0048     {0x6000, 0x006e}, {0x6002, 0x0070}, {0x6094, 0x0071}, {0x60c1, 0x0073},
0049     {0x6034, 0x003d}, {0x6057, 0x005a}, {0x60bb, 0x004f}, {0x609c, 0x0050},
0050     {0x6080, 0x006d}, {0x6002, 0x0039}, {0x6033, 0x003a}, {0x60f1, 0x003b},
0051     {0x6031, 0x003c}, {0x6000, 0x00ff}, {0x6014, 0x00e0}, {0x60ff, 0x0076},
0052     {0x60a0, 0x0033}, {0x6020, 0x0042}, {0x6018, 0x0043}, {0x6000, 0x004c},
0053     {0x60d0, 0x0087}, {0x600f, 0x0088}, {0x6003, 0x00d7}, {0x6010, 0x00d9},
0054     {0x6005, 0x00da}, {0x6082, 0x00d3}, {0x60c0, 0x00f9}, {0x6006, 0x0044},
0055     {0x6007, 0x00d1}, {0x6002, 0x00d2}, {0x6000, 0x00d2}, {0x6011, 0x00d8},
0056     {0x6008, 0x00c8}, {0x6080, 0x00c9}, {0x6008, 0x007c}, {0x6020, 0x007d},
0057     {0x6020, 0x007d}, {0x6000, 0x0090}, {0x600e, 0x0091}, {0x601a, 0x0091},
0058     {0x6031, 0x0091}, {0x605a, 0x0091}, {0x6069, 0x0091}, {0x6075, 0x0091},
0059     {0x607e, 0x0091}, {0x6088, 0x0091}, {0x608f, 0x0091}, {0x6096, 0x0091},
0060     {0x60a3, 0x0091}, {0x60af, 0x0091}, {0x60c4, 0x0091}, {0x60d7, 0x0091},
0061     {0x60e8, 0x0091}, {0x6020, 0x0091}, {0x6000, 0x0092}, {0x6006, 0x0093},
0062     {0x60e3, 0x0093}, {0x6005, 0x0093}, {0x6005, 0x0093}, {0x6000, 0x0093},
0063     {0x6004, 0x0093}, {0x6000, 0x0093}, {0x6000, 0x0093}, {0x6000, 0x0093},
0064     {0x6000, 0x0093}, {0x6000, 0x0093}, {0x6000, 0x0093}, {0x6000, 0x0093},
0065     {0x6000, 0x0096}, {0x6008, 0x0097}, {0x6019, 0x0097}, {0x6002, 0x0097},
0066     {0x600c, 0x0097}, {0x6024, 0x0097}, {0x6030, 0x0097}, {0x6028, 0x0097},
0067     {0x6026, 0x0097}, {0x6002, 0x0097}, {0x6098, 0x0097}, {0x6080, 0x0097},
0068     {0x6000, 0x0097}, {0x6000, 0x0097}, {0x60ed, 0x00c3}, {0x609a, 0x00c4},
0069     {0x6000, 0x00a4}, {0x6011, 0x00c5}, {0x6051, 0x00c6}, {0x6010, 0x00c7},
0070     {0x6066, 0x00b6}, {0x60a5, 0x00b8}, {0x6064, 0x00b7}, {0x607c, 0x00b9},
0071     {0x60af, 0x00b3}, {0x6097, 0x00b4}, {0x60ff, 0x00b5}, {0x60c5, 0x00b0},
0072     {0x6094, 0x00b1}, {0x600f, 0x00b2}, {0x605c, 0x00c4}, {0x6000, 0x00a8},
0073     {0x60c8, 0x00c0}, {0x6096, 0x00c1}, {0x601d, 0x0086}, {0x6000, 0x0050},
0074     {0x6090, 0x0051}, {0x6018, 0x0052}, {0x6000, 0x0053}, {0x6000, 0x0054},
0075     {0x6088, 0x0055}, {0x6000, 0x0057}, {0x6090, 0x005a}, {0x6018, 0x005b},
0076     {0x6005, 0x005c}, {0x60ed, 0x00c3}, {0x6000, 0x007f}, {0x6005, 0x00da},
0077     {0x601f, 0x00e5}, {0x6067, 0x00e1}, {0x6000, 0x00e0}, {0x60ff, 0x00dd},
0078     {0x6000, 0x0005}, {0x6001, 0x00ff}, {0x6000, 0x0000}, {0x6000, 0x0045},
0079     {0x6000, 0x0010},
0080 };
0081 
0082 static struct validx tbl_sensor_settings_common1[] = {
0083     {0x0041, 0x0000}, {0x006a, 0x0007}, {0x00ef, 0x0006}, {0x006a, 0x000d},
0084     {0x0000, 0x00c0}, {0x0010, 0x0010}, {0x0001, 0x00c1}, {0x0041, 0x00c2},
0085     {0x0004, 0x00d8}, {0x0012, 0x0004}, {0x0000, 0x0058}, {0x0041, 0x0000},
0086     {50, 0xffff},
0087     {0x0061, 0x0000},
0088     {0xffff, 0xffff},
0089     {0x6000, 0x00ff}, {0x6000, 0x007c}, {0x6007, 0x007d},
0090     {30, 0xffff},
0091     {0x0040, 0x0000},
0092 };
0093 
0094 static struct validx tbl_sensor_settings_common2[] = {
0095     {0x6001, 0x00ff}, {0x6038, 0x000c},
0096     {10, 0xffff},
0097     {0x6000, 0x0011},
0098 };
0099 
0100 static struct validx tbl_640[] = {
0101     {0x6000, 0x00ff}, {0x60f1, 0x00dd}, {0x6004, 0x00e0}, {0x6067, 0x00e1},
0102     {0x6004, 0x00da}, {0x6000, 0x00ff}, {0x60f1, 0x00dd}, {0x6004, 0x00e0},
0103     {0x6001, 0x00ff}, {0x6000, 0x0012}, {0x6000, 0x0011}, {0x6011, 0x0017},
0104     {0x6075, 0x0018}, {0x6001, 0x0019}, {0x6097, 0x001a}, {0x6036, 0x0032},
0105     {0x60bb, 0x004f}, {0x6057, 0x005a}, {0x609c, 0x0050}, {0x6080, 0x006d},
0106     {0x6092, 0x0026}, {0x60ff, 0x0020}, {0x6000, 0x0027}, {0x6000, 0x00ff},
0107     {0x60c8, 0x00c0}, {0x6096, 0x00c1}, {0x6000, 0x008c}, {0x603d, 0x0086},
0108     {0x6089, 0x0050}, {0x6090, 0x0051}, {0x602c, 0x0052}, {0x6000, 0x0053},
0109     {0x6000, 0x0054}, {0x6088, 0x0055}, {0x6000, 0x0057}, {0x60a0, 0x005a},
0110     {0x6078, 0x005b}, {0x6000, 0x005c}, {0x6004, 0x00d3}, {0x6000, 0x00e0},
0111     {0x60ff, 0x00dd}, {0x60a1, 0x005a},
0112 };
0113 
0114 static struct validx tbl_800[] = {
0115     {0x6000, 0x00ff}, {0x60f1, 0x00dd}, {0x6004, 0x00e0}, {0x6067, 0x00e1},
0116     {0x6004, 0x00da}, {0x6000, 0x00ff}, {0x60f1, 0x00dd}, {0x6004, 0x00e0},
0117     {0x6001, 0x00ff}, {0x6040, 0x0012}, {0x6000, 0x0011}, {0x6011, 0x0017},
0118     {0x6043, 0x0018}, {0x6000, 0x0019}, {0x604b, 0x001a}, {0x6009, 0x0032},
0119     {0x60ca, 0x004f}, {0x60a8, 0x0050}, {0x6000, 0x006d}, {0x6038, 0x003d},
0120     {0x60c8, 0x0035}, {0x6000, 0x0022}, {0x6092, 0x0026}, {0x60ff, 0x0020},
0121     {0x6000, 0x0027}, {0x6000, 0x00ff}, {0x6064, 0x00c0}, {0x604b, 0x00c1},
0122     {0x6000, 0x008c}, {0x601d, 0x0086}, {0x6082, 0x00d3}, {0x6000, 0x00e0},
0123     {0x60ff, 0x00dd}, {0x6020, 0x008c}, {0x6001, 0x00ff}, {0x6044, 0x0018},
0124 };
0125 
0126 static struct validx tbl_big1[] = {
0127     {0x0002, 0x00c1}, {0x6000, 0x00ff}, {0x60f1, 0x00dd}, {0x6004, 0x00e0},
0128     {0x6001, 0x00ff}, {0x6000, 0x0012}, {0x6000, 0x0000}, {0x6000, 0x0045},
0129     {0x6000, 0x0010}, {0x6000, 0x0011}, {0x6011, 0x0017}, {0x6075, 0x0018},
0130     {0x6001, 0x0019}, {0x6097, 0x001a}, {0x6036, 0x0032}, {0x60bb, 0x004f},
0131     {0x609c, 0x0050}, {0x6057, 0x005a}, {0x6080, 0x006d}, {0x6043, 0x000f},
0132     {0x608f, 0x0003}, {0x6005, 0x007c}, {0x6081, 0x0026}, {0x6000, 0x00ff},
0133     {0x60c8, 0x00c0}, {0x6096, 0x00c1}, {0x6000, 0x008c},
0134 };
0135 
0136 static struct validx tbl_big2[] = {
0137     {0x603d, 0x0086}, {0x6000, 0x0050}, {0x6090, 0x0051}, {0x602c, 0x0052},
0138     {0x6000, 0x0053}, {0x6000, 0x0054}, {0x6088, 0x0055}, {0x6000, 0x0057},
0139     {0x6040, 0x005a}, {0x60f0, 0x005b}, {0x6001, 0x005c}, {0x6082, 0x00d3},
0140     {0x6000, 0x008e},
0141 };
0142 
0143 static struct validx tbl_big3[] = {
0144     {0x6004, 0x00da}, {0x6000, 0x00e0}, {0x6067, 0x00e1}, {0x60ff, 0x00dd},
0145     {0x6001, 0x00ff}, {0x6000, 0x00ff}, {0x60f1, 0x00dd}, {0x6004, 0x00e0},
0146     {0x6001, 0x00ff}, {0x6000, 0x0011}, {0x6000, 0x00ff}, {0x6010, 0x00c7},
0147     {0x6000, 0x0092}, {0x6006, 0x0093}, {0x60e3, 0x0093}, {0x6005, 0x0093},
0148     {0x6005, 0x0093}, {0x60ed, 0x00c3}, {0x6000, 0x00a4}, {0x60d0, 0x0087},
0149     {0x6003, 0x0096}, {0x600c, 0x0097}, {0x6024, 0x0097}, {0x6030, 0x0097},
0150     {0x6028, 0x0097}, {0x6026, 0x0097}, {0x6002, 0x0097}, {0x6001, 0x00ff},
0151     {0x6043, 0x000f}, {0x608f, 0x0003}, {0x6000, 0x002d}, {0x6000, 0x002e},
0152     {0x600a, 0x0022}, {0x6002, 0x0070}, {0x6008, 0x0014}, {0x6048, 0x0014},
0153     {0x6000, 0x00ff}, {0x6000, 0x00e0}, {0x60ff, 0x00dd},
0154 };
0155 
0156 static struct validx tbl_post_unset_alt[] = {
0157     {0x006a, 0x000d}, {0x6001, 0x00ff}, {0x6081, 0x0026}, {0x6000, 0x0000},
0158     {0x6000, 0x0045}, {0x6000, 0x0010}, {0x6068, 0x000d},
0159     {50, 0xffff},
0160     {0x0021, 0x0000},
0161 };
0162 
0163 static int  ov2640_init_at_startup(struct gspca_dev *gspca_dev);
0164 static int  ov2640_configure_alt(struct gspca_dev *gspca_dev);
0165 static int  ov2640_init_pre_alt(struct gspca_dev *gspca_dev);
0166 static int  ov2640_init_post_alt(struct gspca_dev *gspca_dev);
0167 static void ov2640_post_unset_alt(struct gspca_dev *gspca_dev);
0168 static int  ov2640_camera_settings(struct gspca_dev *gspca_dev);
0169 /*==========================================================================*/
0170 
0171 void ov2640_init_settings(struct gspca_dev *gspca_dev)
0172 {
0173     struct sd *sd = (struct sd *) gspca_dev;
0174 
0175     sd->vcur.backlight  =  32;
0176     sd->vcur.brightness =   0;
0177     sd->vcur.sharpness  =   6;
0178     sd->vcur.contrast   =   0;
0179     sd->vcur.gamma      =  32;
0180     sd->vcur.hue        =   0;
0181     sd->vcur.saturation = 128;
0182     sd->vcur.whitebal   =  64;
0183     sd->vcur.mirror     =   0;
0184     sd->vcur.flip       =   0;
0185 
0186     sd->vmax.backlight  =  64;
0187     sd->vmax.brightness = 255;
0188     sd->vmax.sharpness  =  31;
0189     sd->vmax.contrast   = 255;
0190     sd->vmax.gamma      =  64;
0191     sd->vmax.hue        = 254 + 2;
0192     sd->vmax.saturation = 255;
0193     sd->vmax.whitebal   = 128;
0194     sd->vmax.mirror     = 1;
0195     sd->vmax.flip       = 1;
0196     sd->vmax.AC50Hz     = 0;
0197 
0198     sd->dev_camera_settings = ov2640_camera_settings;
0199     sd->dev_init_at_startup = ov2640_init_at_startup;
0200     sd->dev_configure_alt   = ov2640_configure_alt;
0201     sd->dev_init_pre_alt    = ov2640_init_pre_alt;
0202     sd->dev_post_unset_alt  = ov2640_post_unset_alt;
0203 }
0204 
0205 /*==========================================================================*/
0206 
0207 static void common(struct gspca_dev *gspca_dev)
0208 {
0209     fetch_validx(gspca_dev, tbl_common, ARRAY_SIZE(tbl_common));
0210 }
0211 
0212 static int ov2640_init_at_startup(struct gspca_dev *gspca_dev)
0213 {
0214     fetch_validx(gspca_dev, tbl_init_at_startup,
0215             ARRAY_SIZE(tbl_init_at_startup));
0216 
0217     ctrl_out(gspca_dev, 0x40, 3, 0x0000, 0x0200, 12, dat_init1);
0218 
0219     common(gspca_dev);
0220 
0221     ctrl_in(gspca_dev, 0xc0, 2, 0x0000, 0x0006, 1, c61);
0222 
0223     ctrl_out(gspca_dev, 0x40, 1, 0x00ef, 0x0006, 0, NULL);
0224 
0225     ctrl_in(gspca_dev, 0xc0, 2, 0x0000, 0x0000, 1, c51);
0226 
0227     ctrl_out(gspca_dev, 0x40, 1, 0x0051, 0x0000, 0, NULL);
0228 /*  ctrl_out(gspca_dev, 0x40, 11, 0x0000, 0x0000, 0, NULL); */
0229 
0230     return 0;
0231 }
0232 
0233 static int ov2640_init_pre_alt(struct gspca_dev *gspca_dev)
0234 {
0235     struct sd *sd = (struct sd *) gspca_dev;
0236 
0237     sd->mirrorMask = 0;
0238 
0239     sd->vold.backlight  = -1;
0240     sd->vold.brightness = -1;
0241     sd->vold.sharpness  = -1;
0242     sd->vold.contrast   = -1;
0243     sd->vold.saturation = -1;
0244     sd->vold.gamma    = -1;
0245     sd->vold.hue      = -1;
0246     sd->vold.whitebal = -1;
0247     sd->vold.mirror = -1;
0248     sd->vold.flip   = -1;
0249 
0250     ov2640_init_post_alt(gspca_dev);
0251 
0252     return 0;
0253 }
0254 
0255 static int ov2640_init_post_alt(struct gspca_dev *gspca_dev)
0256 {
0257     s32 reso = gspca_dev->cam.cam_mode[(s32) gspca_dev->curr_mode].priv;
0258     s32 n; /* reserved for FETCH functions */
0259 
0260     ctrl_out(gspca_dev, 0x40, 5, 0x0001, 0x0000, 0, NULL);
0261 
0262     n = fetch_validx(gspca_dev, tbl_sensor_settings_common1,
0263             ARRAY_SIZE(tbl_sensor_settings_common1));
0264     ctrl_out(gspca_dev, 0x40, 3, 0x0000, 0x0200, 12, dat_post);
0265     common(gspca_dev);
0266     keep_on_fetching_validx(gspca_dev, tbl_sensor_settings_common1,
0267                 ARRAY_SIZE(tbl_sensor_settings_common1), n);
0268 
0269     switch (reso) {
0270     case IMAGE_640:
0271         n = fetch_validx(gspca_dev, tbl_640, ARRAY_SIZE(tbl_640));
0272         ctrl_out(gspca_dev, 0x40, 3, 0x0000, 0x0200, 12, dat_640);
0273         break;
0274 
0275     case IMAGE_800:
0276         n = fetch_validx(gspca_dev, tbl_800, ARRAY_SIZE(tbl_800));
0277         ctrl_out(gspca_dev, 0x40, 3, 0x0000, 0x0200, 12, dat_800);
0278         break;
0279 
0280     case IMAGE_1600:
0281     case IMAGE_1280:
0282         n = fetch_validx(gspca_dev, tbl_big1, ARRAY_SIZE(tbl_big1));
0283 
0284         if (reso == IMAGE_1280) {
0285             n = fetch_validx(gspca_dev, tbl_big2,
0286                     ARRAY_SIZE(tbl_big2));
0287         } else {
0288             ctrl_out(gspca_dev, 0x40, 1, 0x601d, 0x0086, 0, NULL);
0289             ctrl_out(gspca_dev, 0x40, 1, 0x6001, 0x00d7, 0, NULL);
0290             ctrl_out(gspca_dev, 0x40, 1, 0x6082, 0x00d3, 0, NULL);
0291         }
0292 
0293         n = fetch_validx(gspca_dev, tbl_big3, ARRAY_SIZE(tbl_big3));
0294 
0295         if (reso == IMAGE_1280) {
0296             ctrl_out(gspca_dev, 0x40, 1, 0x6001, 0x00ff, 0, NULL);
0297             ctrl_out(gspca_dev, 0x40, 3, 0x0000, 0x0200,
0298                     12, dat_1280);
0299         } else {
0300             ctrl_out(gspca_dev, 0x40, 1, 0x6020, 0x008c, 0, NULL);
0301             ctrl_out(gspca_dev, 0x40, 1, 0x6001, 0x00ff, 0, NULL);
0302             ctrl_out(gspca_dev, 0x40, 1, 0x6076, 0x0018, 0, NULL);
0303             ctrl_out(gspca_dev, 0x40, 3, 0x0000, 0x0200,
0304                     12, dat_1600);
0305         }
0306         break;
0307     }
0308 
0309     n = fetch_validx(gspca_dev, tbl_sensor_settings_common2,
0310             ARRAY_SIZE(tbl_sensor_settings_common2));
0311 
0312     ov2640_camera_settings(gspca_dev);
0313 
0314     return 0;
0315 }
0316 
0317 static int ov2640_configure_alt(struct gspca_dev *gspca_dev)
0318 {
0319     s32 reso = gspca_dev->cam.cam_mode[(s32) gspca_dev->curr_mode].priv;
0320 
0321     switch (reso) {
0322     case IMAGE_640:
0323         gspca_dev->alt = 3 + 1;
0324         break;
0325 
0326     case IMAGE_800:
0327     case IMAGE_1280:
0328     case IMAGE_1600:
0329         gspca_dev->alt = 1 + 1;
0330         break;
0331     }
0332     return 0;
0333 }
0334 
0335 static int ov2640_camera_settings(struct gspca_dev *gspca_dev)
0336 {
0337     struct sd *sd = (struct sd *) gspca_dev;
0338 
0339     s32 backlight = sd->vcur.backlight;
0340     s32 bright = sd->vcur.brightness;
0341     s32 sharp  = sd->vcur.sharpness;
0342     s32 gam    = sd->vcur.gamma;
0343     s32 cntr   = sd->vcur.contrast;
0344     s32 sat    = sd->vcur.saturation;
0345     s32 hue    = sd->vcur.hue;
0346     s32 wbal   = sd->vcur.whitebal;
0347     s32 mirror = (((sd->vcur.mirror > 0) ^ sd->mirrorMask) == 0);
0348     s32 flip   = (((sd->vcur.flip   > 0) ^ sd->mirrorMask) == 0);
0349 
0350     if (backlight != sd->vold.backlight) {
0351         /* No sd->vold.backlight=backlight; (to be done again later) */
0352         if (backlight < 0 || backlight > sd->vmax.backlight)
0353             backlight = 0;
0354 
0355         ctrl_out(gspca_dev, 0x40, 1, 0x6001                 , 0x00ff,
0356                 0, NULL);
0357         ctrl_out(gspca_dev, 0x40, 1, 0x601e + backlight     , 0x0024,
0358                 0, NULL);
0359         ctrl_out(gspca_dev, 0x40, 1, 0x601e + backlight - 10, 0x0025,
0360                 0, NULL);
0361     }
0362 
0363     if (bright != sd->vold.brightness) {
0364         sd->vold.brightness = bright;
0365         if (bright < 0 || bright > sd->vmax.brightness)
0366             bright = 0;
0367 
0368         ctrl_out(gspca_dev, 0x40, 1, 0x6000         , 0x00ff, 0, NULL);
0369         ctrl_out(gspca_dev, 0x40, 1, 0x6009         , 0x007c, 0, NULL);
0370         ctrl_out(gspca_dev, 0x40, 1, 0x6000 + bright, 0x007d, 0, NULL);
0371     }
0372 
0373     if (wbal != sd->vold.whitebal) {
0374         sd->vold.whitebal = wbal;
0375         if (wbal < 0 || wbal > sd->vmax.whitebal)
0376             wbal = 0;
0377 
0378         ctrl_out(gspca_dev, 0x40, 1, 0x6000       , 0x00ff, 0, NULL);
0379         ctrl_out(gspca_dev, 0x40, 1, 0x6003       , 0x007c, 0, NULL);
0380         ctrl_out(gspca_dev, 0x40, 1, 0x6000 + wbal, 0x007d, 0, NULL);
0381     }
0382 
0383     if (cntr != sd->vold.contrast) {
0384         sd->vold.contrast = cntr;
0385         if (cntr < 0 || cntr > sd->vmax.contrast)
0386             cntr = 0;
0387 
0388         ctrl_out(gspca_dev, 0x40, 1, 0x6000       , 0x00ff, 0, NULL);
0389         ctrl_out(gspca_dev, 0x40, 1, 0x6007       , 0x007c, 0, NULL);
0390         ctrl_out(gspca_dev, 0x40, 1, 0x6000 + cntr, 0x007d, 0, NULL);
0391     }
0392 
0393     if (sat != sd->vold.saturation) {
0394         sd->vold.saturation = sat;
0395         if (sat < 0 || sat > sd->vmax.saturation)
0396             sat = 0;
0397 
0398         ctrl_out(gspca_dev, 0x40, 1, 0x6000      , 0x00ff, 0, NULL);
0399         ctrl_out(gspca_dev, 0x40, 1, 0x6001      , 0x007c, 0, NULL);
0400         ctrl_out(gspca_dev, 0x40, 1, 0x6000 + sat, 0x007d, 0, NULL);
0401     }
0402 
0403     if (sharp != sd->vold.sharpness) {
0404         sd->vold.sharpness = sharp;
0405         if (sharp < 0 || sharp > sd->vmax.sharpness)
0406             sharp = 0;
0407 
0408         ctrl_out(gspca_dev, 0x40, 1, 0x6000        , 0x00ff, 0, NULL);
0409         ctrl_out(gspca_dev, 0x40, 1, 0x6001        , 0x0092, 0, NULL);
0410         ctrl_out(gspca_dev, 0x40, 1, 0x60c0 + sharp, 0x0093, 0, NULL);
0411     }
0412 
0413     if (hue != sd->vold.hue) {
0414         sd->vold.hue = hue;
0415         if (hue < 0 || hue > sd->vmax.hue)
0416             hue = 0;
0417 
0418         ctrl_out(gspca_dev, 0x40, 1, 0x6000     , 0x00ff, 0, NULL);
0419         ctrl_out(gspca_dev, 0x40, 1, 0x6002     , 0x007c, 0, NULL);
0420         ctrl_out(gspca_dev, 0x40, 1, 0x6000 + hue * (hue < 255), 0x007d,
0421                 0, NULL);
0422         if (hue >= 255)
0423             sd->swapRB = 1;
0424         else
0425             sd->swapRB = 0;
0426     }
0427 
0428     if (gam != sd->vold.gamma) {
0429         sd->vold.gamma = gam;
0430         if (gam < 0 || gam > sd->vmax.gamma)
0431             gam = 0;
0432 
0433         ctrl_out(gspca_dev, 0x40, 1, 0x6000      , 0x00ff, 0, NULL);
0434         ctrl_out(gspca_dev, 0x40, 1, 0x6008      , 0x007c, 0, NULL);
0435         ctrl_out(gspca_dev, 0x40, 1, 0x6000 + gam, 0x007d, 0, NULL);
0436     }
0437 
0438     if (mirror != sd->vold.mirror || flip != sd->vold.flip) {
0439         sd->vold.mirror = mirror;
0440         sd->vold.flip   = flip;
0441 
0442         mirror = 0x80 * mirror;
0443         ctrl_out(gspca_dev, 0x40, 1, 0x6001, 0x00ff, 0, NULL);
0444         ctrl_out(gspca_dev, 0x40, 1, 0x6000, 0x8004, 0, NULL);
0445         ctrl_in(gspca_dev, 0xc0, 2, 0x6000, 0x8004, 1, c28);
0446         ctrl_out(gspca_dev, 0x40, 1, 0x6028 + mirror, 0x0004, 0, NULL);
0447 
0448         flip = 0x50 * flip + mirror;
0449         ctrl_out(gspca_dev, 0x40, 1, 0x6001, 0x00ff, 0, NULL);
0450         ctrl_out(gspca_dev, 0x40, 1, 0x6000, 0x8004, 0, NULL);
0451         ctrl_in(gspca_dev, 0xc0, 2, 0x6000, 0x8004, 1, ca8);
0452         ctrl_out(gspca_dev, 0x40, 1, 0x6028 + flip, 0x0004, 0, NULL);
0453 
0454         ctrl_in(gspca_dev, 0xc0, 2, 0x0000, 0x0000, 1, c50);
0455     }
0456 
0457     if (backlight != sd->vold.backlight) {
0458         sd->vold.backlight = backlight;
0459 
0460         ctrl_out(gspca_dev, 0x40, 1, 0x6001                 , 0x00ff,
0461                 0, NULL);
0462         ctrl_out(gspca_dev, 0x40, 1, 0x601e + backlight     , 0x0024,
0463                 0, NULL);
0464         ctrl_out(gspca_dev, 0x40, 1, 0x601e + backlight - 10, 0x0025,
0465                 0, NULL);
0466     }
0467 
0468     return 0;
0469 }
0470 
0471 static void ov2640_post_unset_alt(struct gspca_dev *gspca_dev)
0472 {
0473     ctrl_out(gspca_dev, 0x40, 5, 0x0000, 0x0000, 0, NULL);
0474     msleep(20);
0475     fetch_validx(gspca_dev, tbl_post_unset_alt,
0476             ARRAY_SIZE(tbl_post_unset_alt));
0477 }