[TG3]: Set minimal hw interrupt mitigation.
[linux-2.6/verdex.git] / drivers / usb / media / sn9c102_pas202bcb.c
blob5ca54c7daaf2bebf1305d6a2afa1e35bc4135641
1 /***************************************************************************
2 * Plug-in for PAS202BCB image sensor connected to the SN9C10x PC Camera *
3 * Controllers *
4 * *
5 * Copyright (C) 2004 by Carlos Eduardo Medaglia Dyonisio *
6 * <medaglia@undl.org.br> *
7 * http://cadu.homelinux.com:8080/ *
8 * *
9 * DAC Magnitude, exposure and green gain controls added by *
10 * Luca Risolia <luca.risolia@studio.unibo.it> *
11 * *
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 * (at your option) any later version. *
16 * *
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. *
21 * *
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., 675 Mass Ave, Cambridge, MA 02139, USA. *
25 ***************************************************************************/
27 #include <linux/delay.h>
28 #include "sn9c102_sensor.h"
31 static struct sn9c102_sensor pas202bcb;
34 static int pas202bcb_init(struct sn9c102_device* cam)
36 int err = 0;
38 err += sn9c102_write_reg(cam, 0x00, 0x10);
39 err += sn9c102_write_reg(cam, 0x00, 0x11);
40 err += sn9c102_write_reg(cam, 0x00, 0x14);
41 err += sn9c102_write_reg(cam, 0x20, 0x17);
42 err += sn9c102_write_reg(cam, 0x30, 0x19);
43 err += sn9c102_write_reg(cam, 0x09, 0x18);
45 err += sn9c102_i2c_write(cam, 0x02, 0x14);
46 err += sn9c102_i2c_write(cam, 0x03, 0x40);
47 err += sn9c102_i2c_write(cam, 0x0d, 0x2c);
48 err += sn9c102_i2c_write(cam, 0x0e, 0x01);
49 err += sn9c102_i2c_write(cam, 0x0f, 0xa9);
50 err += sn9c102_i2c_write(cam, 0x10, 0x08);
51 err += sn9c102_i2c_write(cam, 0x13, 0x63);
52 err += sn9c102_i2c_write(cam, 0x15, 0x70);
53 err += sn9c102_i2c_write(cam, 0x11, 0x01);
55 msleep(400);
57 return err;
61 static int pas202bcb_get_ctrl(struct sn9c102_device* cam,
62 struct v4l2_control* ctrl)
64 switch (ctrl->id) {
65 case V4L2_CID_EXPOSURE:
67 int r1 = sn9c102_i2c_read(cam, 0x04),
68 r2 = sn9c102_i2c_read(cam, 0x05);
69 if (r1 < 0 || r2 < 0)
70 return -EIO;
71 ctrl->value = (r1 << 6) | (r2 & 0x3f);
73 return 0;
74 case V4L2_CID_RED_BALANCE:
75 if ((ctrl->value = sn9c102_i2c_read(cam, 0x09)) < 0)
76 return -EIO;
77 ctrl->value &= 0x0f;
78 return 0;
79 case V4L2_CID_BLUE_BALANCE:
80 if ((ctrl->value = sn9c102_i2c_read(cam, 0x07)) < 0)
81 return -EIO;
82 ctrl->value &= 0x0f;
83 return 0;
84 case V4L2_CID_GAIN:
85 if ((ctrl->value = sn9c102_i2c_read(cam, 0x10)) < 0)
86 return -EIO;
87 ctrl->value &= 0x1f;
88 return 0;
89 case SN9C102_V4L2_CID_GREEN_BALANCE:
90 if ((ctrl->value = sn9c102_i2c_read(cam, 0x08)) < 0)
91 return -EIO;
92 ctrl->value &= 0x0f;
93 return 0;
94 case SN9C102_V4L2_CID_DAC_MAGNITUDE:
95 if ((ctrl->value = sn9c102_i2c_read(cam, 0x0c)) < 0)
96 return -EIO;
97 return 0;
98 default:
99 return -EINVAL;
104 static int pas202bcb_set_pix_format(struct sn9c102_device* cam,
105 const struct v4l2_pix_format* pix)
107 int err = 0;
109 if (pix->pixelformat == V4L2_PIX_FMT_SN9C10X)
110 err += sn9c102_write_reg(cam, 0x24, 0x17);
111 else
112 err += sn9c102_write_reg(cam, 0x20, 0x17);
114 return err;
118 static int pas202bcb_set_ctrl(struct sn9c102_device* cam,
119 const struct v4l2_control* ctrl)
121 int err = 0;
123 switch (ctrl->id) {
124 case V4L2_CID_EXPOSURE:
125 err += sn9c102_i2c_write(cam, 0x04, ctrl->value >> 6);
126 err += sn9c102_i2c_write(cam, 0x05, ctrl->value & 0x3f);
127 break;
128 case V4L2_CID_RED_BALANCE:
129 err += sn9c102_i2c_write(cam, 0x09, ctrl->value);
130 break;
131 case V4L2_CID_BLUE_BALANCE:
132 err += sn9c102_i2c_write(cam, 0x07, ctrl->value);
133 break;
134 case V4L2_CID_GAIN:
135 err += sn9c102_i2c_write(cam, 0x10, ctrl->value);
136 break;
137 case SN9C102_V4L2_CID_GREEN_BALANCE:
138 err += sn9c102_i2c_write(cam, 0x08, ctrl->value);
139 break;
140 case SN9C102_V4L2_CID_DAC_MAGNITUDE:
141 err += sn9c102_i2c_write(cam, 0x0c, ctrl->value);
142 break;
143 default:
144 return -EINVAL;
146 err += sn9c102_i2c_write(cam, 0x11, 0x01);
148 return err ? -EIO : 0;
152 static int pas202bcb_set_crop(struct sn9c102_device* cam,
153 const struct v4l2_rect* rect)
155 struct sn9c102_sensor* s = &pas202bcb;
156 int err = 0;
157 u8 h_start = (u8)(rect->left - s->cropcap.bounds.left) + 4,
158 v_start = (u8)(rect->top - s->cropcap.bounds.top) + 3;
160 err += sn9c102_write_reg(cam, h_start, 0x12);
161 err += sn9c102_write_reg(cam, v_start, 0x13);
163 return err;
167 static struct sn9c102_sensor pas202bcb = {
168 .name = "PAS202BCB",
169 .maintainer = "Carlos Eduardo Medaglia Dyonisio "
170 "<medaglia@undl.org.br>",
171 .sysfs_ops = SN9C102_I2C_READ | SN9C102_I2C_WRITE,
172 .frequency = SN9C102_I2C_400KHZ | SN9C102_I2C_100KHZ,
173 .interface = SN9C102_I2C_2WIRES,
174 .i2c_slave_id = 0x40,
175 .init = &pas202bcb_init,
176 .qctrl = {
178 .id = V4L2_CID_EXPOSURE,
179 .type = V4L2_CTRL_TYPE_INTEGER,
180 .name = "exposure",
181 .minimum = 0x01e5,
182 .maximum = 0x3fff,
183 .step = 0x0001,
184 .default_value = 0x01e5,
185 .flags = 0,
188 .id = V4L2_CID_GAIN,
189 .type = V4L2_CTRL_TYPE_INTEGER,
190 .name = "global gain",
191 .minimum = 0x00,
192 .maximum = 0x1f,
193 .step = 0x01,
194 .default_value = 0x0c,
195 .flags = 0,
198 .id = V4L2_CID_RED_BALANCE,
199 .type = V4L2_CTRL_TYPE_INTEGER,
200 .name = "red balance",
201 .minimum = 0x00,
202 .maximum = 0x0f,
203 .step = 0x01,
204 .default_value = 0x01,
205 .flags = 0,
208 .id = V4L2_CID_BLUE_BALANCE,
209 .type = V4L2_CTRL_TYPE_INTEGER,
210 .name = "blue balance",
211 .minimum = 0x00,
212 .maximum = 0x0f,
213 .step = 0x01,
214 .default_value = 0x05,
215 .flags = 0,
218 .id = SN9C102_V4L2_CID_GREEN_BALANCE,
219 .type = V4L2_CTRL_TYPE_INTEGER,
220 .name = "green balance",
221 .minimum = 0x00,
222 .maximum = 0x0f,
223 .step = 0x01,
224 .default_value = 0x00,
225 .flags = 0,
228 .id = SN9C102_V4L2_CID_DAC_MAGNITUDE,
229 .type = V4L2_CTRL_TYPE_INTEGER,
230 .name = "DAC magnitude",
231 .minimum = 0x00,
232 .maximum = 0xff,
233 .step = 0x01,
234 .default_value = 0x04,
235 .flags = 0,
238 .get_ctrl = &pas202bcb_get_ctrl,
239 .set_ctrl = &pas202bcb_set_ctrl,
240 .cropcap = {
241 .bounds = {
242 .left = 0,
243 .top = 0,
244 .width = 640,
245 .height = 480,
247 .defrect = {
248 .left = 0,
249 .top = 0,
250 .width = 640,
251 .height = 480,
254 .set_crop = &pas202bcb_set_crop,
255 .pix_format = {
256 .width = 640,
257 .height = 480,
258 .pixelformat = V4L2_PIX_FMT_SBGGR8,
259 .priv = 8,
261 .set_pix_format = &pas202bcb_set_pix_format
265 int sn9c102_probe_pas202bcb(struct sn9c102_device* cam)
267 int r0 = 0, r1 = 0, err = 0;
268 unsigned int pid = 0;
271 * Minimal initialization to enable the I2C communication
272 * NOTE: do NOT change the values!
274 err += sn9c102_write_reg(cam, 0x01, 0x01); /* sensor power down */
275 err += sn9c102_write_reg(cam, 0x40, 0x01); /* sensor power on */
276 err += sn9c102_write_reg(cam, 0x28, 0x17); /* sensor clock at 24 MHz */
277 if (err)
278 return -EIO;
280 r0 = sn9c102_i2c_try_read(cam, &pas202bcb, 0x00);
281 r1 = sn9c102_i2c_try_read(cam, &pas202bcb, 0x01);
283 if (r0 < 0 || r1 < 0)
284 return -EIO;
286 pid = (r0 << 4) | ((r1 & 0xf0) >> 4);
287 if (pid != 0x017)
288 return -ENODEV;
290 sn9c102_attach_sensor(cam, &pas202bcb);
292 return 0;