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_const_regs(cam
, {0x00, 0x10}, {0x00, 0x11},
30 {0x00, 0x14}, {0x60, 0x17},
31 {0x0e, 0x18}, {0xf2, 0x19});
33 err
+= sn9c102_i2c_write(cam
, 0x01, 0x04);
34 err
+= sn9c102_i2c_write(cam
, 0x02, 0x00);
35 err
+= sn9c102_i2c_write(cam
, 0x28, 0x00);
41 static int hv7131d_get_ctrl(struct sn9c102_device
* cam
,
42 struct v4l2_control
* ctrl
)
45 case V4L2_CID_EXPOSURE
:
47 int r1
= sn9c102_i2c_read(cam
, 0x26),
48 r2
= sn9c102_i2c_read(cam
, 0x27);
51 ctrl
->value
= (r1
<< 8) | (r2
& 0xff);
54 case V4L2_CID_RED_BALANCE
:
55 if ((ctrl
->value
= sn9c102_i2c_read(cam
, 0x31)) < 0)
57 ctrl
->value
= 0x3f - (ctrl
->value
& 0x3f);
59 case V4L2_CID_BLUE_BALANCE
:
60 if ((ctrl
->value
= sn9c102_i2c_read(cam
, 0x33)) < 0)
62 ctrl
->value
= 0x3f - (ctrl
->value
& 0x3f);
64 case SN9C102_V4L2_CID_GREEN_BALANCE
:
65 if ((ctrl
->value
= sn9c102_i2c_read(cam
, 0x32)) < 0)
67 ctrl
->value
= 0x3f - (ctrl
->value
& 0x3f);
69 case SN9C102_V4L2_CID_RESET_LEVEL
:
70 if ((ctrl
->value
= sn9c102_i2c_read(cam
, 0x30)) < 0)
74 case SN9C102_V4L2_CID_PIXEL_BIAS_VOLTAGE
:
75 if ((ctrl
->value
= sn9c102_i2c_read(cam
, 0x34)) < 0)
85 static int hv7131d_set_ctrl(struct sn9c102_device
* cam
,
86 const struct v4l2_control
* ctrl
)
91 case V4L2_CID_EXPOSURE
:
92 err
+= sn9c102_i2c_write(cam
, 0x26, ctrl
->value
>> 8);
93 err
+= sn9c102_i2c_write(cam
, 0x27, ctrl
->value
& 0xff);
95 case V4L2_CID_RED_BALANCE
:
96 err
+= sn9c102_i2c_write(cam
, 0x31, 0x3f - ctrl
->value
);
98 case V4L2_CID_BLUE_BALANCE
:
99 err
+= sn9c102_i2c_write(cam
, 0x33, 0x3f - ctrl
->value
);
101 case SN9C102_V4L2_CID_GREEN_BALANCE
:
102 err
+= sn9c102_i2c_write(cam
, 0x32, 0x3f - ctrl
->value
);
104 case SN9C102_V4L2_CID_RESET_LEVEL
:
105 err
+= sn9c102_i2c_write(cam
, 0x30, ctrl
->value
);
107 case SN9C102_V4L2_CID_PIXEL_BIAS_VOLTAGE
:
108 err
+= sn9c102_i2c_write(cam
, 0x34, ctrl
->value
);
114 return err
? -EIO
: 0;
118 static int hv7131d_set_crop(struct sn9c102_device
* cam
,
119 const struct v4l2_rect
* rect
)
121 struct sn9c102_sensor
* s
= sn9c102_get_sensor(cam
);
123 u8 h_start
= (u8
)(rect
->left
- s
->cropcap
.bounds
.left
) + 2,
124 v_start
= (u8
)(rect
->top
- s
->cropcap
.bounds
.top
) + 2;
126 err
+= sn9c102_write_reg(cam
, h_start
, 0x12);
127 err
+= sn9c102_write_reg(cam
, v_start
, 0x13);
133 static int hv7131d_set_pix_format(struct sn9c102_device
* cam
,
134 const struct v4l2_pix_format
* pix
)
138 if (pix
->pixelformat
== V4L2_PIX_FMT_SN9C10X
)
139 err
+= sn9c102_write_reg(cam
, 0x42, 0x19);
141 err
+= sn9c102_write_reg(cam
, 0xf2, 0x19);
147 static const struct sn9c102_sensor hv7131d
= {
149 .maintainer
= "Luca Risolia <luca.risolia@studio.unibo.it>",
150 .supported_bridge
= BRIDGE_SN9C101
| BRIDGE_SN9C102
,
151 .sysfs_ops
= SN9C102_I2C_READ
| SN9C102_I2C_WRITE
,
152 .frequency
= SN9C102_I2C_100KHZ
,
153 .interface
= SN9C102_I2C_2WIRES
,
154 .i2c_slave_id
= 0x11,
155 .init
= &hv7131d_init
,
158 .id
= V4L2_CID_EXPOSURE
,
159 .type
= V4L2_CTRL_TYPE_INTEGER
,
164 .default_value
= 0x0250,
168 .id
= V4L2_CID_RED_BALANCE
,
169 .type
= V4L2_CTRL_TYPE_INTEGER
,
170 .name
= "red balance",
174 .default_value
= 0x00,
178 .id
= V4L2_CID_BLUE_BALANCE
,
179 .type
= V4L2_CTRL_TYPE_INTEGER
,
180 .name
= "blue balance",
184 .default_value
= 0x20,
188 .id
= SN9C102_V4L2_CID_GREEN_BALANCE
,
189 .type
= V4L2_CTRL_TYPE_INTEGER
,
190 .name
= "green balance",
194 .default_value
= 0x1e,
198 .id
= SN9C102_V4L2_CID_RESET_LEVEL
,
199 .type
= V4L2_CTRL_TYPE_INTEGER
,
200 .name
= "reset level",
204 .default_value
= 0x30,
208 .id
= SN9C102_V4L2_CID_PIXEL_BIAS_VOLTAGE
,
209 .type
= V4L2_CTRL_TYPE_INTEGER
,
210 .name
= "pixel bias voltage",
214 .default_value
= 0x02,
218 .get_ctrl
= &hv7131d_get_ctrl
,
219 .set_ctrl
= &hv7131d_set_ctrl
,
234 .set_crop
= &hv7131d_set_crop
,
238 .pixelformat
= V4L2_PIX_FMT_SBGGR8
,
241 .set_pix_format
= &hv7131d_set_pix_format
245 int sn9c102_probe_hv7131d(struct sn9c102_device
* cam
)
247 int r0
= 0, r1
= 0, err
;
249 err
= sn9c102_write_const_regs(cam
, {0x01, 0x01}, {0x00, 0x01},
252 r0
= sn9c102_i2c_try_read(cam
, &hv7131d
, 0x00);
253 r1
= sn9c102_i2c_try_read(cam
, &hv7131d
, 0x01);
254 if (err
|| r0
< 0 || r1
< 0)
257 if (r0
!= 0x00 || r1
!= 0x04)
260 sn9c102_attach_sensor(cam
, &hv7131d
);