1 /***************************************************************************
2 * Plug-in for HV7131D image sensor connected to the SN9C1xx PC Camera *
5 * Copyright (C) 2004-2007 by Luca Risolia <luca.risolia@studio.unibo.it> *
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 * (at your option) any later version. *
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. *
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., 675 Mass Ave, Cambridge, MA 02139, USA. *
20 ***************************************************************************/
22 #include "sn9c102_sensor.h"
25 static int hv7131d_init(struct sn9c102_device* cam)
29 err += sn9c102_write_reg(cam, 0x00, 0x10);
30 err += sn9c102_write_reg(cam, 0x00, 0x11);
31 err += sn9c102_write_reg(cam, 0x00, 0x14);
32 err += sn9c102_write_reg(cam, 0x60, 0x17);
33 err += sn9c102_write_reg(cam, 0x0e, 0x18);
34 err += sn9c102_write_reg(cam, 0xf2, 0x19);
36 err += sn9c102_i2c_write(cam, 0x01, 0x04);
37 err += sn9c102_i2c_write(cam, 0x02, 0x00);
38 err += sn9c102_i2c_write(cam, 0x28, 0x00);
44 static int hv7131d_get_ctrl(struct sn9c102_device* cam,
45 struct v4l2_control* ctrl)
48 case V4L2_CID_EXPOSURE:
50 int r1 = sn9c102_i2c_read(cam, 0x26),
51 r2 = sn9c102_i2c_read(cam, 0x27);
54 ctrl->value = (r1 << 8) | (r2 & 0xff);
57 case V4L2_CID_RED_BALANCE:
58 if ((ctrl->value = sn9c102_i2c_read(cam, 0x31)) < 0)
60 ctrl->value = 0x3f - (ctrl->value & 0x3f);
62 case V4L2_CID_BLUE_BALANCE:
63 if ((ctrl->value = sn9c102_i2c_read(cam, 0x33)) < 0)
65 ctrl->value = 0x3f - (ctrl->value & 0x3f);
67 case SN9C102_V4L2_CID_GREEN_BALANCE:
68 if ((ctrl->value = sn9c102_i2c_read(cam, 0x32)) < 0)
70 ctrl->value = 0x3f - (ctrl->value & 0x3f);
72 case SN9C102_V4L2_CID_RESET_LEVEL:
73 if ((ctrl->value = sn9c102_i2c_read(cam, 0x30)) < 0)
77 case SN9C102_V4L2_CID_PIXEL_BIAS_VOLTAGE:
78 if ((ctrl->value = sn9c102_i2c_read(cam, 0x34)) < 0)
88 static int hv7131d_set_ctrl(struct sn9c102_device* cam,
89 const struct v4l2_control* ctrl)
94 case V4L2_CID_EXPOSURE:
95 err += sn9c102_i2c_write(cam, 0x26, ctrl->value >> 8);
96 err += sn9c102_i2c_write(cam, 0x27, ctrl->value & 0xff);
98 case V4L2_CID_RED_BALANCE:
99 err += sn9c102_i2c_write(cam, 0x31, 0x3f - ctrl->value);
101 case V4L2_CID_BLUE_BALANCE:
102 err += sn9c102_i2c_write(cam, 0x33, 0x3f - ctrl->value);
104 case SN9C102_V4L2_CID_GREEN_BALANCE:
105 err += sn9c102_i2c_write(cam, 0x32, 0x3f - ctrl->value);
107 case SN9C102_V4L2_CID_RESET_LEVEL:
108 err += sn9c102_i2c_write(cam, 0x30, ctrl->value);
110 case SN9C102_V4L2_CID_PIXEL_BIAS_VOLTAGE:
111 err += sn9c102_i2c_write(cam, 0x34, ctrl->value);
117 return err ? -EIO : 0;
121 static int hv7131d_set_crop(struct sn9c102_device* cam,
122 const struct v4l2_rect* rect)
124 struct sn9c102_sensor* s = sn9c102_get_sensor(cam);
126 u8 h_start = (u8)(rect->left - s->cropcap.bounds.left) + 2,
127 v_start = (u8)(rect->top - s->cropcap.bounds.top) + 2;
129 err += sn9c102_write_reg(cam, h_start, 0x12);
130 err += sn9c102_write_reg(cam, v_start, 0x13);
136 static int hv7131d_set_pix_format(struct sn9c102_device* cam,
137 const struct v4l2_pix_format* pix)
141 if (pix->pixelformat == V4L2_PIX_FMT_SN9C10X)
142 err += sn9c102_write_reg(cam, 0x42, 0x19);
144 err += sn9c102_write_reg(cam, 0xf2, 0x19);
150 static struct sn9c102_sensor hv7131d = {
152 .maintainer = "Luca Risolia <luca.risolia@studio.unibo.it>",
153 .supported_bridge = BRIDGE_SN9C101 | BRIDGE_SN9C102,
154 .sysfs_ops = SN9C102_I2C_READ | SN9C102_I2C_WRITE,
155 .frequency = SN9C102_I2C_100KHZ,
156 .interface = SN9C102_I2C_2WIRES,
157 .i2c_slave_id = 0x11,
158 .init = &hv7131d_init,
161 .id = V4L2_CID_EXPOSURE,
162 .type = V4L2_CTRL_TYPE_INTEGER,
167 .default_value = 0x0250,
171 .id = V4L2_CID_RED_BALANCE,
172 .type = V4L2_CTRL_TYPE_INTEGER,
173 .name = "red balance",
177 .default_value = 0x00,
181 .id = V4L2_CID_BLUE_BALANCE,
182 .type = V4L2_CTRL_TYPE_INTEGER,
183 .name = "blue balance",
187 .default_value = 0x20,
191 .id = SN9C102_V4L2_CID_GREEN_BALANCE,
192 .type = V4L2_CTRL_TYPE_INTEGER,
193 .name = "green balance",
197 .default_value = 0x1e,
201 .id = SN9C102_V4L2_CID_RESET_LEVEL,
202 .type = V4L2_CTRL_TYPE_INTEGER,
203 .name = "reset level",
207 .default_value = 0x30,
211 .id = SN9C102_V4L2_CID_PIXEL_BIAS_VOLTAGE,
212 .type = V4L2_CTRL_TYPE_INTEGER,
213 .name = "pixel bias voltage",
217 .default_value = 0x02,
221 .get_ctrl = &hv7131d_get_ctrl,
222 .set_ctrl = &hv7131d_set_ctrl,
237 .set_crop = &hv7131d_set_crop,
241 .pixelformat = V4L2_PIX_FMT_SBGGR8,
244 .set_pix_format = &hv7131d_set_pix_format
248 int sn9c102_probe_hv7131d(struct sn9c102_device* cam)
250 int r0 = 0, r1 = 0, err = 0;
252 err += sn9c102_write_reg(cam, 0x01, 0x01);
253 err += sn9c102_write_reg(cam, 0x00, 0x01);
254 err += sn9c102_write_reg(cam, 0x28, 0x17);
258 r0 = sn9c102_i2c_try_read(cam, &hv7131d, 0x00);
259 r1 = sn9c102_i2c_try_read(cam, &hv7131d, 0x01);
260 if (r0 < 0 || r1 < 0)
263 if (r0 != 0x00 || r1 != 0x04)
266 sn9c102_attach_sensor(cam, &hv7131d);