1 /***************************************************************************
2 * Plug-in for PAS202BCA image sensor connected to the SN9C10x PC Camera *
5 * Copyright (C) 2006 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 pas202bca
;
29 static int pas202bca_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
, 0x30, 0x19);
38 err
+= sn9c102_write_reg(cam
, 0x09, 0x18);
40 err
+= sn9c102_i2c_write(cam
, 0x02, 0x14);
41 err
+= sn9c102_i2c_write(cam
, 0x03, 0x40);
42 err
+= sn9c102_i2c_write(cam
, 0x0d, 0x2c);
43 err
+= sn9c102_i2c_write(cam
, 0x0e, 0x01);
44 err
+= sn9c102_i2c_write(cam
, 0x0f, 0xa9);
45 err
+= sn9c102_i2c_write(cam
, 0x10, 0x08);
46 err
+= sn9c102_i2c_write(cam
, 0x13, 0x63);
47 err
+= sn9c102_i2c_write(cam
, 0x15, 0x70);
48 err
+= sn9c102_i2c_write(cam
, 0x11, 0x01);
56 static int pas202bca_set_pix_format(struct sn9c102_device
* cam
,
57 const struct v4l2_pix_format
* pix
)
61 if (pix
->pixelformat
== V4L2_PIX_FMT_SN9C10X
)
62 err
+= sn9c102_write_reg(cam
, 0x24, 0x17);
64 err
+= sn9c102_write_reg(cam
, 0x20, 0x17);
70 static int pas202bca_set_ctrl(struct sn9c102_device
* cam
,
71 const struct v4l2_control
* ctrl
)
76 case V4L2_CID_EXPOSURE
:
77 err
+= sn9c102_i2c_write(cam
, 0x04, ctrl
->value
>> 6);
78 err
+= sn9c102_i2c_write(cam
, 0x05, ctrl
->value
& 0x3f);
80 case V4L2_CID_RED_BALANCE
:
81 err
+= sn9c102_i2c_write(cam
, 0x09, ctrl
->value
);
83 case V4L2_CID_BLUE_BALANCE
:
84 err
+= sn9c102_i2c_write(cam
, 0x07, ctrl
->value
);
87 err
+= sn9c102_i2c_write(cam
, 0x10, ctrl
->value
);
89 case SN9C102_V4L2_CID_GREEN_BALANCE
:
90 err
+= sn9c102_i2c_write(cam
, 0x08, ctrl
->value
);
92 case SN9C102_V4L2_CID_DAC_MAGNITUDE
:
93 err
+= sn9c102_i2c_write(cam
, 0x0c, ctrl
->value
);
98 err
+= sn9c102_i2c_write(cam
, 0x11, 0x01);
100 return err
? -EIO
: 0;
104 static int pas202bca_set_crop(struct sn9c102_device
* cam
,
105 const struct v4l2_rect
* rect
)
107 struct sn9c102_sensor
* s
= &pas202bca
;
109 u8 h_start
= (u8
)(rect
->left
- s
->cropcap
.bounds
.left
) + 3,
110 v_start
= (u8
)(rect
->top
- s
->cropcap
.bounds
.top
) + 3;
112 err
+= sn9c102_write_reg(cam
, h_start
, 0x12);
113 err
+= sn9c102_write_reg(cam
, v_start
, 0x13);
119 static struct sn9c102_sensor pas202bca
= {
121 .maintainer
= "Luca Risolia <luca.risolia@studio.unibo.it>",
122 .sysfs_ops
= SN9C102_I2C_READ
| SN9C102_I2C_WRITE
,
123 .frequency
= SN9C102_I2C_400KHZ
| SN9C102_I2C_100KHZ
,
124 .interface
= SN9C102_I2C_2WIRES
,
125 .i2c_slave_id
= 0x40,
126 .init
= &pas202bca_init
,
129 .id
= V4L2_CID_EXPOSURE
,
130 .type
= V4L2_CTRL_TYPE_INTEGER
,
135 .default_value
= 0x01e5,
140 .type
= V4L2_CTRL_TYPE_INTEGER
,
141 .name
= "global gain",
145 .default_value
= 0x0c,
149 .id
= V4L2_CID_RED_BALANCE
,
150 .type
= V4L2_CTRL_TYPE_INTEGER
,
151 .name
= "red balance",
155 .default_value
= 0x01,
159 .id
= V4L2_CID_BLUE_BALANCE
,
160 .type
= V4L2_CTRL_TYPE_INTEGER
,
161 .name
= "blue balance",
165 .default_value
= 0x05,
169 .id
= SN9C102_V4L2_CID_GREEN_BALANCE
,
170 .type
= V4L2_CTRL_TYPE_INTEGER
,
171 .name
= "green balance",
175 .default_value
= 0x00,
179 .id
= SN9C102_V4L2_CID_DAC_MAGNITUDE
,
180 .type
= V4L2_CTRL_TYPE_INTEGER
,
181 .name
= "DAC magnitude",
185 .default_value
= 0x04,
189 .set_ctrl
= &pas202bca_set_ctrl
,
204 .set_crop
= &pas202bca_set_crop
,
208 .pixelformat
= V4L2_PIX_FMT_SBGGR8
,
211 .set_pix_format
= &pas202bca_set_pix_format
215 int sn9c102_probe_pas202bca(struct sn9c102_device
* cam
)
217 const struct usb_device_id pas202bca_id_table
[] = {
218 { USB_DEVICE(0x0c45, 0x60af), },
223 if (!sn9c102_match_id(cam
,pas202bca_id_table
))
226 err
+= sn9c102_write_reg(cam
, 0x01, 0x01);
227 err
+= sn9c102_write_reg(cam
, 0x40, 0x01);
228 err
+= sn9c102_write_reg(cam
, 0x28, 0x17);
232 if (sn9c102_i2c_try_write(cam
, &pas202bca
, 0x10, 0)) /* try to write */
235 sn9c102_attach_sensor(cam
, &pas202bca
);