1 /***************************************************************************
2 * Plug-in for PAS106B image sensor connected to the SN9C10x PC Camera *
5 * Copyright (C) 2004-2005 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 <linux/delay.h>
23 #include "sn9c102_sensor.h"
26 static struct sn9c102_sensor pas106b
;
29 static int pas106b_init(struct sn9c102_device
* cam
)
33 err
+= sn9c102_write_reg(cam
, 0x00, 0x10);
34 err
+= sn9c102_write_reg(cam
, 0x00, 0x11);
35 err
+= sn9c102_write_reg(cam
, 0x00, 0x14);
36 err
+= sn9c102_write_reg(cam
, 0x20, 0x17);
37 err
+= sn9c102_write_reg(cam
, 0x20, 0x19);
38 err
+= sn9c102_write_reg(cam
, 0x09, 0x18);
40 err
+= sn9c102_i2c_write(cam
, 0x02, 0x0c);
41 err
+= sn9c102_i2c_write(cam
, 0x05, 0x5a);
42 err
+= sn9c102_i2c_write(cam
, 0x06, 0x88);
43 err
+= sn9c102_i2c_write(cam
, 0x07, 0x80);
44 err
+= sn9c102_i2c_write(cam
, 0x10, 0x06);
45 err
+= sn9c102_i2c_write(cam
, 0x11, 0x06);
46 err
+= sn9c102_i2c_write(cam
, 0x12, 0x00);
47 err
+= sn9c102_i2c_write(cam
, 0x14, 0x02);
48 err
+= sn9c102_i2c_write(cam
, 0x13, 0x01);
56 static int pas106b_get_ctrl(struct sn9c102_device
* cam
,
57 struct v4l2_control
* ctrl
)
60 case V4L2_CID_EXPOSURE
:
62 int r1
= sn9c102_i2c_read(cam
, 0x03),
63 r2
= sn9c102_i2c_read(cam
, 0x04);
66 ctrl
->value
= (r1
<< 4) | (r2
& 0x0f);
69 case V4L2_CID_RED_BALANCE
:
70 if ((ctrl
->value
= sn9c102_i2c_read(cam
, 0x0c)) < 0)
74 case V4L2_CID_BLUE_BALANCE
:
75 if ((ctrl
->value
= sn9c102_i2c_read(cam
, 0x09)) < 0)
80 if ((ctrl
->value
= sn9c102_i2c_read(cam
, 0x0e)) < 0)
84 case V4L2_CID_CONTRAST
:
85 if ((ctrl
->value
= sn9c102_i2c_read(cam
, 0x0f)) < 0)
89 case SN9C102_V4L2_CID_GREEN_BALANCE
:
90 if ((ctrl
->value
= sn9c102_i2c_read(cam
, 0x0a)) < 0)
92 ctrl
->value
= (ctrl
->value
& 0x1f) << 1;
94 case SN9C102_V4L2_CID_DAC_MAGNITUDE
:
95 if ((ctrl
->value
= sn9c102_i2c_read(cam
, 0x08)) < 0)
105 static int pas106b_set_ctrl(struct sn9c102_device
* cam
,
106 const struct v4l2_control
* ctrl
)
111 case V4L2_CID_EXPOSURE
:
112 err
+= sn9c102_i2c_write(cam
, 0x03, ctrl
->value
>> 4);
113 err
+= sn9c102_i2c_write(cam
, 0x04, ctrl
->value
& 0x0f);
115 case V4L2_CID_RED_BALANCE
:
116 err
+= sn9c102_i2c_write(cam
, 0x0c, ctrl
->value
);
118 case V4L2_CID_BLUE_BALANCE
:
119 err
+= sn9c102_i2c_write(cam
, 0x09, ctrl
->value
);
122 err
+= sn9c102_i2c_write(cam
, 0x0e, ctrl
->value
);
124 case V4L2_CID_CONTRAST
:
125 err
+= sn9c102_i2c_write(cam
, 0x0f, ctrl
->value
);
127 case SN9C102_V4L2_CID_GREEN_BALANCE
:
128 err
+= sn9c102_i2c_write(cam
, 0x0a, ctrl
->value
>> 1);
129 err
+= sn9c102_i2c_write(cam
, 0x0b, ctrl
->value
>> 1);
131 case SN9C102_V4L2_CID_DAC_MAGNITUDE
:
132 err
+= sn9c102_i2c_write(cam
, 0x08, ctrl
->value
<< 3);
137 err
+= sn9c102_i2c_write(cam
, 0x13, 0x01);
139 return err
? -EIO
: 0;
143 static int pas106b_set_crop(struct sn9c102_device
* cam
,
144 const struct v4l2_rect
* rect
)
146 struct sn9c102_sensor
* s
= &pas106b
;
148 u8 h_start
= (u8
)(rect
->left
- s
->cropcap
.bounds
.left
) + 4,
149 v_start
= (u8
)(rect
->top
- s
->cropcap
.bounds
.top
) + 3;
151 err
+= sn9c102_write_reg(cam
, h_start
, 0x12);
152 err
+= sn9c102_write_reg(cam
, v_start
, 0x13);
158 static int pas106b_set_pix_format(struct sn9c102_device
* cam
,
159 const struct v4l2_pix_format
* pix
)
163 if (pix
->pixelformat
== V4L2_PIX_FMT_SN9C10X
)
164 err
+= sn9c102_write_reg(cam
, 0x2c, 0x17);
166 err
+= sn9c102_write_reg(cam
, 0x20, 0x17);
172 static struct sn9c102_sensor pas106b
= {
174 .maintainer
= "Luca Risolia <luca.risolia@studio.unibo.it>",
175 .sysfs_ops
= SN9C102_I2C_READ
| SN9C102_I2C_WRITE
,
176 .frequency
= SN9C102_I2C_400KHZ
| SN9C102_I2C_100KHZ
,
177 .interface
= SN9C102_I2C_2WIRES
,
178 .i2c_slave_id
= 0x40,
179 .init
= &pas106b_init
,
182 .id
= V4L2_CID_EXPOSURE
,
183 .type
= V4L2_CTRL_TYPE_INTEGER
,
188 .default_value
= 0x140,
193 .type
= V4L2_CTRL_TYPE_INTEGER
,
194 .name
= "global gain",
198 .default_value
= 0x0d,
202 .id
= V4L2_CID_CONTRAST
,
203 .type
= V4L2_CTRL_TYPE_INTEGER
,
208 .default_value
= 0x00, /* 0x00~0x03 have same effect */
212 .id
= V4L2_CID_RED_BALANCE
,
213 .type
= V4L2_CTRL_TYPE_INTEGER
,
214 .name
= "red balance",
218 .default_value
= 0x04,
222 .id
= V4L2_CID_BLUE_BALANCE
,
223 .type
= V4L2_CTRL_TYPE_INTEGER
,
224 .name
= "blue balance",
228 .default_value
= 0x06,
232 .id
= SN9C102_V4L2_CID_GREEN_BALANCE
,
233 .type
= V4L2_CTRL_TYPE_INTEGER
,
234 .name
= "green balance",
238 .default_value
= 0x02,
242 .id
= SN9C102_V4L2_CID_DAC_MAGNITUDE
,
243 .type
= V4L2_CTRL_TYPE_INTEGER
,
244 .name
= "DAC magnitude",
248 .default_value
= 0x01,
252 .get_ctrl
= &pas106b_get_ctrl
,
253 .set_ctrl
= &pas106b_set_ctrl
,
268 .set_crop
= &pas106b_set_crop
,
272 .pixelformat
= V4L2_PIX_FMT_SBGGR8
,
273 .priv
= 8, /* we use this field as 'bits per pixel' */
275 .set_pix_format
= &pas106b_set_pix_format
279 int sn9c102_probe_pas106b(struct sn9c102_device
* cam
)
281 int r0
= 0, r1
= 0, err
= 0;
282 unsigned int pid
= 0;
285 Minimal initialization to enable the I2C communication
286 NOTE: do NOT change the values!
288 err
+= sn9c102_write_reg(cam
, 0x01, 0x01); /* sensor power down */
289 err
+= sn9c102_write_reg(cam
, 0x00, 0x01); /* sensor power on */
290 err
+= sn9c102_write_reg(cam
, 0x28, 0x17); /* sensor clock at 24 MHz */
294 r0
= sn9c102_i2c_try_read(cam
, &pas106b
, 0x00);
295 r1
= sn9c102_i2c_try_read(cam
, &pas106b
, 0x01);
297 if (r0
< 0 || r1
< 0)
300 pid
= (r0
<< 11) | ((r1
& 0xf0) >> 4);
304 sn9c102_attach_sensor(cam
, &pas106b
);