1 /***************************************************************************
2 * Plug-in for MT9V111 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 mt9v111_init(struct sn9c102_device
*cam
)
27 struct sn9c102_sensor
*s
= sn9c102_get_sensor(cam
);
30 err
= sn9c102_write_const_regs(cam
, {0x44, 0x01}, {0x40, 0x02},
31 {0x00, 0x03}, {0x1a, 0x04},
32 {0x1f, 0x05}, {0x20, 0x06},
33 {0x1f, 0x07}, {0x81, 0x08},
34 {0x5c, 0x09}, {0x00, 0x0a},
35 {0x00, 0x0b}, {0x00, 0x0c},
36 {0x00, 0x0d}, {0x00, 0x0e},
37 {0x00, 0x0f}, {0x03, 0x10},
38 {0x00, 0x11}, {0x00, 0x12},
39 {0x02, 0x13}, {0x14, 0x14},
40 {0x28, 0x15}, {0x1e, 0x16},
41 {0xe2, 0x17}, {0x06, 0x18},
42 {0x00, 0x19}, {0x00, 0x1a},
43 {0x00, 0x1b}, {0x08, 0x20},
44 {0x39, 0x21}, {0x51, 0x22},
45 {0x63, 0x23}, {0x73, 0x24},
46 {0x82, 0x25}, {0x8f, 0x26},
47 {0x9b, 0x27}, {0xa7, 0x28},
48 {0xb1, 0x29}, {0xbc, 0x2a},
49 {0xc6, 0x2b}, {0xcf, 0x2c},
50 {0xd8, 0x2d}, {0xe1, 0x2e},
51 {0xea, 0x2f}, {0xf2, 0x30},
52 {0x13, 0x84}, {0x00, 0x85},
53 {0x25, 0x86}, {0x00, 0x87},
54 {0x07, 0x88}, {0x00, 0x89},
55 {0xee, 0x8a}, {0x0f, 0x8b},
56 {0xe5, 0x8c}, {0x0f, 0x8d},
57 {0x2e, 0x8e}, {0x00, 0x8f},
58 {0x30, 0x90}, {0x00, 0x91},
59 {0xd4, 0x92}, {0x0f, 0x93},
60 {0xfc, 0x94}, {0x0f, 0x95},
61 {0x14, 0x96}, {0x00, 0x97},
62 {0x00, 0x98}, {0x60, 0x99},
63 {0x07, 0x9a}, {0x40, 0x9b},
64 {0x20, 0x9c}, {0x00, 0x9d},
65 {0x00, 0x9e}, {0x00, 0x9f},
66 {0x2d, 0xc0}, {0x2d, 0xc1},
67 {0x3a, 0xc2}, {0x05, 0xc3},
68 {0x04, 0xc4}, {0x3f, 0xc5},
69 {0x00, 0xc6}, {0x00, 0xc7},
70 {0x50, 0xc8}, {0x3c, 0xc9},
71 {0x28, 0xca}, {0xd8, 0xcb},
72 {0x14, 0xcc}, {0xec, 0xcd},
73 {0x32, 0xce}, {0xdd, 0xcf},
74 {0x2d, 0xd0}, {0xdd, 0xd1},
75 {0x6a, 0xd2}, {0x50, 0xd3},
76 {0x60, 0xd4}, {0x00, 0xd5},
79 err
+= sn9c102_i2c_try_raw_write(cam
, s
, 4, s
->i2c_slave_id
, 0x01,
81 err
+= sn9c102_i2c_try_raw_write(cam
, s
, 4, s
->i2c_slave_id
, 0x0d,
83 err
+= sn9c102_i2c_try_raw_write(cam
, s
, 4, s
->i2c_slave_id
, 0x0d,
85 err
+= sn9c102_i2c_try_raw_write(cam
, s
, 4, s
->i2c_slave_id
, 0x08,
87 err
+= sn9c102_i2c_try_raw_write(cam
, s
, 4, s
->i2c_slave_id
, 0x01,
89 err
+= sn9c102_i2c_try_raw_write(cam
, s
, 4, s
->i2c_slave_id
, 0x08,
91 err
+= sn9c102_i2c_try_raw_write(cam
, s
, 4, s
->i2c_slave_id
, 0x02,
93 err
+= sn9c102_i2c_try_raw_write(cam
, s
, 4, s
->i2c_slave_id
, 0x03,
95 err
+= sn9c102_i2c_try_raw_write(cam
, s
, 4, s
->i2c_slave_id
, 0x04,
97 err
+= sn9c102_i2c_try_raw_write(cam
, s
, 4, s
->i2c_slave_id
, 0x06,
99 err
+= sn9c102_i2c_try_raw_write(cam
, s
, 4, s
->i2c_slave_id
, 0x05,
101 err
+= sn9c102_i2c_try_raw_write(cam
, s
, 4, s
->i2c_slave_id
, 0x07,
103 err
+= sn9c102_i2c_try_raw_write(cam
, s
, 4, s
->i2c_slave_id
, 0x0c,
105 err
+= sn9c102_i2c_try_raw_write(cam
, s
, 4, s
->i2c_slave_id
, 0x12,
107 err
+= sn9c102_i2c_try_raw_write(cam
, s
, 4, s
->i2c_slave_id
, 0x13,
109 err
+= sn9c102_i2c_try_raw_write(cam
, s
, 4, s
->i2c_slave_id
, 0x1e,
111 err
+= sn9c102_i2c_try_raw_write(cam
, s
, 4, s
->i2c_slave_id
, 0x20,
113 err
+= sn9c102_i2c_try_raw_write(cam
, s
, 4, s
->i2c_slave_id
, 0x20,
115 err
+= sn9c102_i2c_try_raw_write(cam
, s
, 4, s
->i2c_slave_id
, 0x01,
121 static int mt9v111_get_ctrl(struct sn9c102_device
*cam
,
122 struct v4l2_control
*ctrl
)
124 struct sn9c102_sensor
*s
= sn9c102_get_sensor(cam
);
130 if (sn9c102_i2c_try_raw_read(cam
, s
, s
->i2c_slave_id
, 0x20, 2,
133 ctrl
->value
= data
[1] & 0x80 ? 1 : 0;
139 return err
? -EIO
: 0;
142 static int mt9v111_set_ctrl(struct sn9c102_device
*cam
,
143 const struct v4l2_control
*ctrl
)
145 struct sn9c102_sensor
*s
= sn9c102_get_sensor(cam
);
150 err
+= sn9c102_i2c_try_raw_write(cam
, s
, 4, s
->i2c_slave_id
,
152 ctrl
->value
? 0x80 : 0x00,
153 ctrl
->value
? 0x80 : 0x00, 0,
160 return err
? -EIO
: 0;
163 static int mt9v111_set_crop(struct sn9c102_device
*cam
,
164 const struct v4l2_rect
*rect
)
166 struct sn9c102_sensor
*s
= sn9c102_get_sensor(cam
);
168 u8 v_start
= (u8
) (rect
->top
- s
->cropcap
.bounds
.top
) + 2;
170 err
+= sn9c102_write_reg(cam
, v_start
, 0x13);
175 static int mt9v111_set_pix_format(struct sn9c102_device
*cam
,
176 const struct v4l2_pix_format
*pix
)
180 if (pix
->pixelformat
== V4L2_PIX_FMT_SBGGR8
) {
181 err
+= sn9c102_write_reg(cam
, 0xb4, 0x17);
183 err
+= sn9c102_write_reg(cam
, 0xe2, 0x17);
190 static const struct sn9c102_sensor mt9v111
= {
192 .maintainer
= "Luca Risolia <luca.risolia@studio.unibo.it>",
193 .supported_bridge
= BRIDGE_SN9C105
| BRIDGE_SN9C120
,
194 .frequency
= SN9C102_I2C_100KHZ
,
195 .interface
= SN9C102_I2C_2WIRES
,
196 .i2c_slave_id
= 0x5c,
197 .init
= &mt9v111_init
,
200 .id
= V4L2_CID_VFLIP
,
201 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
202 .name
= "vertical mirror",
210 .get_ctrl
= &mt9v111_get_ctrl
,
211 .set_ctrl
= &mt9v111_set_ctrl
,
226 .set_crop
= &mt9v111_set_crop
,
230 .pixelformat
= V4L2_PIX_FMT_SBGGR8
,
233 .set_pix_format
= &mt9v111_set_pix_format
237 int sn9c102_probe_mt9v111(struct sn9c102_device
*cam
)
242 err
+= sn9c102_write_const_regs(cam
, {0x01, 0xf1}, {0x00, 0xf1},
243 {0x29, 0x01}, {0x42, 0x17},
244 {0x62, 0x17}, {0x08, 0x01});
245 err
+= sn9c102_i2c_try_raw_write(cam
, &mt9v111
, 4,
246 mt9v111
.i2c_slave_id
, 0x01, 0x00,
248 if (err
|| sn9c102_i2c_try_raw_read(cam
, &mt9v111
,
249 mt9v111
.i2c_slave_id
, 0x36, 2,
253 if (data
[0] != 0x82 || data
[1] != 0x3a)
256 sn9c102_attach_sensor(cam
, &mt9v111
);