1 /***************************************************************************
2 * Plug-in for MI-0360 image sensor connected to the SN9C1xx PC Camera *
5 * Copyright (C) 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 mi0360_init(struct sn9c102_device
* cam
)
27 struct sn9c102_sensor
* s
= sn9c102_get_sensor(cam
);
30 err
= sn9c102_write_const_regs(cam
, {0x00, 0x10}, {0x00, 0x11},
31 {0x0a, 0x14}, {0x40, 0x01},
32 {0x20, 0x17}, {0x07, 0x18},
33 {0xa0, 0x19}, {0x02, 0x1c},
34 {0x03, 0x1d}, {0x0f, 0x1e},
35 {0x0c, 0x1f}, {0x00, 0x20},
36 {0x10, 0x21}, {0x20, 0x22},
37 {0x30, 0x23}, {0x40, 0x24},
38 {0x50, 0x25}, {0x60, 0x26},
39 {0x70, 0x27}, {0x80, 0x28},
40 {0x90, 0x29}, {0xa0, 0x2a},
41 {0xb0, 0x2b}, {0xc0, 0x2c},
42 {0xd0, 0x2d}, {0xe0, 0x2e},
43 {0xf0, 0x2f}, {0xff, 0x30});
45 err
+= sn9c102_i2c_try_raw_write(cam
, s
, 4, s
->i2c_slave_id
, 0x0d,
47 err
+= sn9c102_i2c_try_raw_write(cam
, s
, 4, s
->i2c_slave_id
, 0x0d,
49 err
+= sn9c102_i2c_try_raw_write(cam
, s
, 4, s
->i2c_slave_id
, 0x03,
51 err
+= sn9c102_i2c_try_raw_write(cam
, s
, 4, s
->i2c_slave_id
, 0x04,
53 err
+= sn9c102_i2c_try_raw_write(cam
, s
, 4, s
->i2c_slave_id
, 0x05,
55 err
+= sn9c102_i2c_try_raw_write(cam
, s
, 4, s
->i2c_slave_id
, 0x06,
57 err
+= sn9c102_i2c_try_raw_write(cam
, s
, 4, s
->i2c_slave_id
, 0x62,
64 static int mi0360_get_ctrl(struct sn9c102_device
* cam
,
65 struct v4l2_control
* ctrl
)
67 struct sn9c102_sensor
* s
= sn9c102_get_sensor(cam
);
71 case V4L2_CID_EXPOSURE
:
72 if (sn9c102_i2c_try_raw_read(cam
, s
, s
->i2c_slave_id
, 0x09,
75 ctrl
->value
= data
[2];
78 if (sn9c102_i2c_try_raw_read(cam
, s
, s
->i2c_slave_id
, 0x35,
81 ctrl
->value
= data
[3];
83 case V4L2_CID_RED_BALANCE
:
84 if (sn9c102_i2c_try_raw_read(cam
, s
, s
->i2c_slave_id
, 0x2c,
87 ctrl
->value
= data
[3];
89 case V4L2_CID_BLUE_BALANCE
:
90 if (sn9c102_i2c_try_raw_read(cam
, s
, s
->i2c_slave_id
, 0x2d,
93 ctrl
->value
= data
[3];
95 case SN9C102_V4L2_CID_GREEN_BALANCE
:
96 if (sn9c102_i2c_try_raw_read(cam
, s
, s
->i2c_slave_id
, 0x2e,
99 ctrl
->value
= data
[3];
102 if (sn9c102_i2c_try_raw_read(cam
, s
, s
->i2c_slave_id
, 0x20,
105 ctrl
->value
= data
[3] & 0x20 ? 1 : 0;
108 if (sn9c102_i2c_try_raw_read(cam
, s
, s
->i2c_slave_id
, 0x20,
111 ctrl
->value
= data
[3] & 0x80 ? 1 : 0;
121 static int mi0360_set_ctrl(struct sn9c102_device
* cam
,
122 const struct v4l2_control
* ctrl
)
124 struct sn9c102_sensor
* s
= sn9c102_get_sensor(cam
);
128 case V4L2_CID_EXPOSURE
:
129 err
+= sn9c102_i2c_try_raw_write(cam
, s
, 4, s
->i2c_slave_id
,
130 0x09, ctrl
->value
, 0x00,
134 err
+= sn9c102_i2c_try_raw_write(cam
, s
, 4, s
->i2c_slave_id
,
135 0x35, 0x03, ctrl
->value
,
138 case V4L2_CID_RED_BALANCE
:
139 err
+= sn9c102_i2c_try_raw_write(cam
, s
, 4, s
->i2c_slave_id
,
140 0x2c, 0x03, ctrl
->value
,
143 case V4L2_CID_BLUE_BALANCE
:
144 err
+= sn9c102_i2c_try_raw_write(cam
, s
, 4, s
->i2c_slave_id
,
145 0x2d, 0x03, ctrl
->value
,
148 case SN9C102_V4L2_CID_GREEN_BALANCE
:
149 err
+= sn9c102_i2c_try_raw_write(cam
, s
, 4, s
->i2c_slave_id
,
150 0x2b, 0x03, ctrl
->value
,
152 err
+= sn9c102_i2c_try_raw_write(cam
, s
, 4, s
->i2c_slave_id
,
153 0x2e, 0x03, ctrl
->value
,
157 err
+= sn9c102_i2c_try_raw_write(cam
, s
, 4, s
->i2c_slave_id
,
158 0x20, ctrl
->value
? 0x40:0x00,
159 ctrl
->value
? 0x20:0x00,
163 err
+= sn9c102_i2c_try_raw_write(cam
, s
, 4, s
->i2c_slave_id
,
164 0x20, ctrl
->value
? 0x80:0x00,
165 ctrl
->value
? 0x80:0x00,
172 return err
? -EIO
: 0;
176 static int mi0360_set_crop(struct sn9c102_device
* cam
,
177 const struct v4l2_rect
* rect
)
179 struct sn9c102_sensor
* s
= sn9c102_get_sensor(cam
);
181 u8 h_start
= (u8
)(rect
->left
- s
->cropcap
.bounds
.left
) + 0,
182 v_start
= (u8
)(rect
->top
- s
->cropcap
.bounds
.top
) + 1;
184 err
+= sn9c102_write_reg(cam
, h_start
, 0x12);
185 err
+= sn9c102_write_reg(cam
, v_start
, 0x13);
191 static int mi0360_set_pix_format(struct sn9c102_device
* cam
,
192 const struct v4l2_pix_format
* pix
)
194 struct sn9c102_sensor
* s
= sn9c102_get_sensor(cam
);
197 if (pix
->pixelformat
== V4L2_PIX_FMT_SN9C10X
) {
198 err
+= sn9c102_i2c_try_raw_write(cam
, s
, 4, s
->i2c_slave_id
,
199 0x0a, 0x00, 0x02, 0, 0);
200 err
+= sn9c102_write_reg(cam
, 0x20, 0x19);
202 err
+= sn9c102_i2c_try_raw_write(cam
, s
, 4, s
->i2c_slave_id
,
203 0x0a, 0x00, 0x05, 0, 0);
204 err
+= sn9c102_write_reg(cam
, 0x60, 0x19);
211 static struct sn9c102_sensor mi0360
= {
213 .maintainer
= "Luca Risolia <luca.risolia@studio.unibo.it>",
214 .supported_bridge
= BRIDGE_SN9C103
,
215 .frequency
= SN9C102_I2C_100KHZ
,
216 .interface
= SN9C102_I2C_2WIRES
,
217 .i2c_slave_id
= 0x5d,
218 .init
= &mi0360_init
,
221 .id
= V4L2_CID_EXPOSURE
,
222 .type
= V4L2_CTRL_TYPE_INTEGER
,
227 .default_value
= 0x05,
232 .type
= V4L2_CTRL_TYPE_INTEGER
,
233 .name
= "global gain",
237 .default_value
= 0x25,
241 .id
= V4L2_CID_HFLIP
,
242 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
243 .name
= "horizontal mirror",
251 .id
= V4L2_CID_VFLIP
,
252 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
253 .name
= "vertical mirror",
261 .id
= V4L2_CID_BLUE_BALANCE
,
262 .type
= V4L2_CTRL_TYPE_INTEGER
,
263 .name
= "blue balance",
267 .default_value
= 0x0f,
271 .id
= V4L2_CID_RED_BALANCE
,
272 .type
= V4L2_CTRL_TYPE_INTEGER
,
273 .name
= "red balance",
277 .default_value
= 0x32,
281 .id
= SN9C102_V4L2_CID_GREEN_BALANCE
,
282 .type
= V4L2_CTRL_TYPE_INTEGER
,
283 .name
= "green balance",
287 .default_value
= 0x25,
291 .get_ctrl
= &mi0360_get_ctrl
,
292 .set_ctrl
= &mi0360_set_ctrl
,
307 .set_crop
= &mi0360_set_crop
,
311 .pixelformat
= V4L2_PIX_FMT_SBGGR8
,
314 .set_pix_format
= &mi0360_set_pix_format
318 int sn9c102_probe_mi0360(struct sn9c102_device
* cam
)
323 err
= sn9c102_write_const_regs(cam
, {0x01, 0x01}, {0x00, 0x01},
328 if (sn9c102_i2c_try_raw_read(cam
, &mi0360
, mi0360
.i2c_slave_id
, 0x00,
332 if (data
[2] != 0x82 || data
[3] != 0x43)
335 sn9c102_attach_sensor(cam
, &mi0360
);