Allow AWB and blue/red gain to be set at the same time
[microdia.git] / hv7131r.c
blobbd65b25feac4b05d63d55ccdd23faa21a1451cf8
1 /**
2 * @file hv7131r.c
3 * @author Josua Grawitter
4 * @date 2008-12-17
6 * @brief Common control functions the HV7131R Image Sensor
8 * @note Copyright (C) Josua Grawitter
10 * @par Licences
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #include "sn9c20x.h"
28 #include "sn9c20x-bridge.h"
30 struct sn9c20x_i2c_regs hv7131r_init[] = {
31 {0x02, 0x08},
32 {0x02, 0x00},
33 {0x01, 0x08},
34 {0x02, 0x00},
35 {0x20, 0x00},
36 {0x21, 0xd0},
37 {0x22, 0x00},
38 {0x23, 0x09},
39 {0x01, 0x08},
40 {0x01, 0x08},
41 {0x01, 0x08},
42 {0x25, 0x07},
43 {0x26, 0xc3},
44 {0x27, 0x50},
45 {0x30, 0x62},
46 {0x31, 0x10},
47 {0x32, 0x06},
48 {0x33, 0x10},
49 {0x20, 0x00},
50 {0x21, 0xd0},
51 {0x22, 0x00},
52 {0x23, 0x09},
53 {0x01, 0x08},
57 int hv7131r_set_exposure(struct usb_sn9c20x *dev)
59 __u8 buf[3];
60 int ret;
61 __u32 val;
63 val = ((dev->vsettings.exposure << 8) * 0xffffff) / 0xffff;
65 buf[0] = (val >> 16) & 0xff;
66 buf[1] = (val >> 8) & 0xff;
67 buf[2] = val & 0xff;
69 ret = sn9c20x_write_i2c_data_ext(dev, 3, 0x25, buf, 0x1e);
71 return ret;
74 int hv7131r_set_gain(struct usb_sn9c20x *dev)
76 __u8 buf;
77 int ret;
79 buf = dev->vsettings.gain;
81 ret = sn9c20x_write_i2c_data_ext(dev, 1, 0x30, &buf, 0x1d);
83 return ret;
86 int hv7131r_set_hvflip(struct usb_sn9c20x *dev)
88 __u8 buf;
89 int ret;
91 ret = sn9c20x_read_i2c_data(dev, 1, 0x01, &buf);
92 if (ret < 0)
93 return ret;
95 if (dev->vsettings.hflip)
96 buf |= 0x02;
97 else
98 buf &= ~0x02;
100 if (dev->vsettings.vflip)
101 buf |= 0x01;
102 else
103 buf &= ~0x01;
105 ret = sn9c20x_write_i2c_data(dev, 1, 0x01, &buf);
107 return ret;