V4l2 controls now have a max range of 255.
[microdia.git] / hv7131r.c
blobf91a22696e0cbe80b268f94e5ee07ba51dec6ef1
1 /**
2 * @file hv7131r.c
3 * @author GWater
4 * @date 2008-12-17
6 * @brief Common control functions the HV7131R Image Sensor
8 * @note Copyright (C) GWater
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 static __u8 hv7131r_init[][2] = {
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},
56 int hv7131r_initialize(struct usb_sn9c20x *dev)
58 int i;
59 int ret = 0;
61 dev->camera.i2c_flags |= SN9C20X_I2C_400KHZ;
63 for (i = 0; i < ARRAY_SIZE(hv7131r_init); i++) {
64 ret = sn9c20x_write_i2c_data(dev, 1, hv7131r_init[i][0],
65 &hv7131r_init[i][1]);
66 if (ret < 0)
67 goto err;
70 return ret;
72 err:
73 UDIA_ERROR("Sensor Init failed (%d)! - line %d\n", ret, i);
74 return ret;
77 int hv7131r_set_exposure(struct usb_sn9c20x *dev)
79 __u8 buf[3];
80 int ret;
81 __u32 val;
83 val = (dev->vsettings.exposure * 0xffffff) / 0xffff;
85 buf[0] = (val >> 16) & 0xff;
86 buf[1] = (val >> 8) & 0xff;
87 buf[2] = val & 0xff;
89 ret = sn9c20x_write_i2c_data_ext(dev, 3, 0x25, buf, 0x1e);
91 return ret;
94 int hv7131r_set_gain(struct usb_sn9c20x *dev)
96 __u8 buf;
97 int ret;
99 buf = (dev->vsettings.gain >> 8) & 0xff;
101 ret = sn9c20x_write_i2c_data_ext(dev, 1, 0x30, &buf, 0x1d);
103 return ret;
106 int hv7131r_set_hvflip(struct usb_sn9c20x *dev)
108 __u8 buf;
109 int ret;
111 ret = sn9c20x_read_i2c_data(dev, 1, 0x01, &buf);
112 if (ret < 0)
113 return ret;
115 if (dev->vsettings.hflip)
116 buf |= 0x02;
117 else
118 buf &= ~0x02;
120 if (dev->vsettings.vflip)
121 buf |= 0x01;
122 else
123 buf &= ~0x01;
125 ret = sn9c20x_write_i2c_data(dev, 1, 0x01, &buf);
127 return ret;