aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/sn9c102/sn9c102_mi0360.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/media/video/sn9c102/sn9c102_mi0360.c')
-rw-r--r--drivers/media/video/sn9c102/sn9c102_mi0360.c220
1 files changed, 167 insertions, 53 deletions
diff --git a/drivers/media/video/sn9c102/sn9c102_mi0360.c b/drivers/media/video/sn9c102/sn9c102_mi0360.c
index 64698acb0b15..f8d81d82e8d5 100644
--- a/drivers/media/video/sn9c102/sn9c102_mi0360.c
+++ b/drivers/media/video/sn9c102/sn9c102_mi0360.c
@@ -27,20 +27,105 @@ static int mi0360_init(struct sn9c102_device* cam)
27 struct sn9c102_sensor* s = sn9c102_get_sensor(cam); 27 struct sn9c102_sensor* s = sn9c102_get_sensor(cam);
28 int err = 0; 28 int err = 0;
29 29
30 err = sn9c102_write_const_regs(cam, {0x00, 0x10}, {0x00, 0x11}, 30 switch (sn9c102_get_bridge(cam)) {
31 {0x0a, 0x14}, {0x40, 0x01}, 31 case BRIDGE_SN9C103:
32 {0x20, 0x17}, {0x07, 0x18}, 32 err = sn9c102_write_const_regs(cam, {0x00, 0x10}, {0x00, 0x11},
33 {0xa0, 0x19}, {0x02, 0x1c}, 33 {0x0a, 0x14}, {0x40, 0x01},
34 {0x03, 0x1d}, {0x0f, 0x1e}, 34 {0x20, 0x17}, {0x07, 0x18},
35 {0x0c, 0x1f}, {0x00, 0x20}, 35 {0xa0, 0x19}, {0x02, 0x1c},
36 {0x10, 0x21}, {0x20, 0x22}, 36 {0x03, 0x1d}, {0x0f, 0x1e},
37 {0x30, 0x23}, {0x40, 0x24}, 37 {0x0c, 0x1f}, {0x00, 0x20},
38 {0x50, 0x25}, {0x60, 0x26}, 38 {0x10, 0x21}, {0x20, 0x22},
39 {0x70, 0x27}, {0x80, 0x28}, 39 {0x30, 0x23}, {0x40, 0x24},
40 {0x90, 0x29}, {0xa0, 0x2a}, 40 {0x50, 0x25}, {0x60, 0x26},
41 {0xb0, 0x2b}, {0xc0, 0x2c}, 41 {0x70, 0x27}, {0x80, 0x28},
42 {0xd0, 0x2d}, {0xe0, 0x2e}, 42 {0x90, 0x29}, {0xa0, 0x2a},
43 {0xf0, 0x2f}, {0xff, 0x30}); 43 {0xb0, 0x2b}, {0xc0, 0x2c},
44 {0xd0, 0x2d}, {0xe0, 0x2e},
45 {0xf0, 0x2f}, {0xff, 0x30});
46 break;
47 case BRIDGE_SN9C105:
48 case BRIDGE_SN9C120:
49 err = sn9c102_write_const_regs(cam, {0x44, 0x01}, {0x40, 0x02},
50 {0x00, 0x03}, {0x1a, 0x04},
51 {0x50, 0x05}, {0x20, 0x06},
52 {0x10, 0x07}, {0x03, 0x10},
53 {0x08, 0x14}, {0xa2, 0x17},
54 {0x47, 0x18}, {0x00, 0x19},
55 {0x1d, 0x1a}, {0x10, 0x1b},
56 {0x02, 0x1c}, {0x03, 0x1d},
57 {0x0f, 0x1e}, {0x0c, 0x1f},
58 {0x00, 0x20}, {0x29, 0x21},
59 {0x40, 0x22}, {0x54, 0x23},
60 {0x66, 0x24}, {0x76, 0x25},
61 {0x85, 0x26}, {0x94, 0x27},
62 {0xa1, 0x28}, {0xae, 0x29},
63 {0xbb, 0x2a}, {0xc7, 0x2b},
64 {0xd3, 0x2c}, {0xde, 0x2d},
65 {0xea, 0x2e}, {0xf4, 0x2f},
66 {0xff, 0x30}, {0x00, 0x3F},
67 {0xC7, 0x40}, {0x01, 0x41},
68 {0x44, 0x42}, {0x00, 0x43},
69 {0x44, 0x44}, {0x00, 0x45},
70 {0x44, 0x46}, {0x00, 0x47},
71 {0xC7, 0x48}, {0x01, 0x49},
72 {0xC7, 0x4A}, {0x01, 0x4B},
73 {0xC7, 0x4C}, {0x01, 0x4D},
74 {0x44, 0x4E}, {0x00, 0x4F},
75 {0x44, 0x50}, {0x00, 0x51},
76 {0x44, 0x52}, {0x00, 0x53},
77 {0xC7, 0x54}, {0x01, 0x55},
78 {0xC7, 0x56}, {0x01, 0x57},
79 {0xC7, 0x58}, {0x01, 0x59},
80 {0x44, 0x5A}, {0x00, 0x5B},
81 {0x44, 0x5C}, {0x00, 0x5D},
82 {0x44, 0x5E}, {0x00, 0x5F},
83 {0xC7, 0x60}, {0x01, 0x61},
84 {0xC7, 0x62}, {0x01, 0x63},
85 {0xC7, 0x64}, {0x01, 0x65},
86 {0x44, 0x66}, {0x00, 0x67},
87 {0x44, 0x68}, {0x00, 0x69},
88 {0x44, 0x6A}, {0x00, 0x6B},
89 {0xC7, 0x6C}, {0x01, 0x6D},
90 {0xC7, 0x6E}, {0x01, 0x6F},
91 {0xC7, 0x70}, {0x01, 0x71},
92 {0x44, 0x72}, {0x00, 0x73},
93 {0x44, 0x74}, {0x00, 0x75},
94 {0x44, 0x76}, {0x00, 0x77},
95 {0xC7, 0x78}, {0x01, 0x79},
96 {0xC7, 0x7A}, {0x01, 0x7B},
97 {0xC7, 0x7C}, {0x01, 0x7D},
98 {0x44, 0x7E}, {0x00, 0x7F},
99 {0x14, 0x84}, {0x00, 0x85},
100 {0x27, 0x86}, {0x00, 0x87},
101 {0x07, 0x88}, {0x00, 0x89},
102 {0xEC, 0x8A}, {0x0f, 0x8B},
103 {0xD8, 0x8C}, {0x0f, 0x8D},
104 {0x3D, 0x8E}, {0x00, 0x8F},
105 {0x3D, 0x90}, {0x00, 0x91},
106 {0xCD, 0x92}, {0x0f, 0x93},
107 {0xf7, 0x94}, {0x0f, 0x95},
108 {0x0C, 0x96}, {0x00, 0x97},
109 {0x00, 0x98}, {0x66, 0x99},
110 {0x05, 0x9A}, {0x00, 0x9B},
111 {0x04, 0x9C}, {0x00, 0x9D},
112 {0x08, 0x9E}, {0x00, 0x9F},
113 {0x2D, 0xC0}, {0x2D, 0xC1},
114 {0x3A, 0xC2}, {0x05, 0xC3},
115 {0x04, 0xC4}, {0x3F, 0xC5},
116 {0x00, 0xC6}, {0x00, 0xC7},
117 {0x50, 0xC8}, {0x3C, 0xC9},
118 {0x28, 0xCA}, {0xD8, 0xCB},
119 {0x14, 0xCC}, {0xEC, 0xCD},
120 {0x32, 0xCE}, {0xDD, 0xCF},
121 {0x32, 0xD0}, {0xDD, 0xD1},
122 {0x6A, 0xD2}, {0x50, 0xD3},
123 {0x00, 0xD4}, {0x00, 0xD5},
124 {0x00, 0xD6});
125 break;
126 default:
127 break;
128 }
44 129
45 err += sn9c102_i2c_try_raw_write(cam, s, 4, s->i2c_slave_id, 0x0d, 130 err += sn9c102_i2c_try_raw_write(cam, s, 4, s->i2c_slave_id, 0x0d,
46 0x00, 0x01, 0, 0); 131 0x00, 0x01, 0, 0);
@@ -65,50 +150,50 @@ static int mi0360_get_ctrl(struct sn9c102_device* cam,
65 struct v4l2_control* ctrl) 150 struct v4l2_control* ctrl)
66{ 151{
67 struct sn9c102_sensor* s = sn9c102_get_sensor(cam); 152 struct sn9c102_sensor* s = sn9c102_get_sensor(cam);
68 u8 data[5+1]; 153 u8 data[2];
69 154
70 switch (ctrl->id) { 155 switch (ctrl->id) {
71 case V4L2_CID_EXPOSURE: 156 case V4L2_CID_EXPOSURE:
72 if (sn9c102_i2c_try_raw_read(cam, s, s->i2c_slave_id, 0x09, 157 if (sn9c102_i2c_try_raw_read(cam, s, s->i2c_slave_id, 0x09, 2,
73 2+1, data) < 0) 158 data) < 0)
74 return -EIO; 159 return -EIO;
75 ctrl->value = data[2]; 160 ctrl->value = data[0];
76 return 0; 161 return 0;
77 case V4L2_CID_GAIN: 162 case V4L2_CID_GAIN:
78 if (sn9c102_i2c_try_raw_read(cam, s, s->i2c_slave_id, 0x35, 163 if (sn9c102_i2c_try_raw_read(cam, s, s->i2c_slave_id, 0x35, 2,
79 2+1, data) < 0) 164 data) < 0)
80 return -EIO; 165 return -EIO;
81 ctrl->value = data[3]; 166 ctrl->value = data[1];
82 return 0; 167 return 0;
83 case V4L2_CID_RED_BALANCE: 168 case V4L2_CID_RED_BALANCE:
84 if (sn9c102_i2c_try_raw_read(cam, s, s->i2c_slave_id, 0x2c, 169 if (sn9c102_i2c_try_raw_read(cam, s, s->i2c_slave_id, 0x2c, 2,
85 2+1, data) < 0) 170 data) < 0)
86 return -EIO; 171 return -EIO;
87 ctrl->value = data[3]; 172 ctrl->value = data[1];
88 return 0; 173 return 0;
89 case V4L2_CID_BLUE_BALANCE: 174 case V4L2_CID_BLUE_BALANCE:
90 if (sn9c102_i2c_try_raw_read(cam, s, s->i2c_slave_id, 0x2d, 175 if (sn9c102_i2c_try_raw_read(cam, s, s->i2c_slave_id, 0x2d, 2,
91 2+1, data) < 0) 176 data) < 0)
92 return -EIO; 177 return -EIO;
93 ctrl->value = data[3]; 178 ctrl->value = data[1];
94 return 0; 179 return 0;
95 case SN9C102_V4L2_CID_GREEN_BALANCE: 180 case SN9C102_V4L2_CID_GREEN_BALANCE:
96 if (sn9c102_i2c_try_raw_read(cam, s, s->i2c_slave_id, 0x2e, 181 if (sn9c102_i2c_try_raw_read(cam, s, s->i2c_slave_id, 0x2e, 2,
97 2+1, data) < 0) 182 data) < 0)
98 return -EIO; 183 return -EIO;
99 ctrl->value = data[3]; 184 ctrl->value = data[1];
100 return 0; 185 return 0;
101 case V4L2_CID_HFLIP: 186 case V4L2_CID_HFLIP:
102 if (sn9c102_i2c_try_raw_read(cam, s, s->i2c_slave_id, 0x20, 187 if (sn9c102_i2c_try_raw_read(cam, s, s->i2c_slave_id, 0x20, 2,
103 2+1, data) < 0) 188 data) < 0)
104 return -EIO; 189 return -EIO;
105 ctrl->value = data[3] & 0x20 ? 1 : 0; 190 ctrl->value = data[1] & 0x20 ? 1 : 0;
106 return 0; 191 return 0;
107 case V4L2_CID_VFLIP: 192 case V4L2_CID_VFLIP:
108 if (sn9c102_i2c_try_raw_read(cam, s, s->i2c_slave_id, 0x20, 193 if (sn9c102_i2c_try_raw_read(cam, s, s->i2c_slave_id, 0x20, 2,
109 2+1, data) < 0) 194 data) < 0)
110 return -EIO; 195 return -EIO;
111 ctrl->value = data[3] & 0x80 ? 1 : 0; 196 ctrl->value = data[1] & 0x80 ? 1 : 0;
112 return 0; 197 return 0;
113 default: 198 default:
114 return -EINVAL; 199 return -EINVAL;
@@ -178,8 +263,19 @@ static int mi0360_set_crop(struct sn9c102_device* cam,
178{ 263{
179 struct sn9c102_sensor* s = sn9c102_get_sensor(cam); 264 struct sn9c102_sensor* s = sn9c102_get_sensor(cam);
180 int err = 0; 265 int err = 0;
181 u8 h_start = (u8)(rect->left - s->cropcap.bounds.left) + 0, 266 u8 h_start = 0, v_start = (u8)(rect->top - s->cropcap.bounds.top) + 1;
182 v_start = (u8)(rect->top - s->cropcap.bounds.top) + 1; 267
268 switch (sn9c102_get_bridge(cam)) {
269 case BRIDGE_SN9C103:
270 h_start = (u8)(rect->left - s->cropcap.bounds.left) + 0;
271 break;
272 case BRIDGE_SN9C105:
273 case BRIDGE_SN9C120:
274 h_start = (u8)(rect->left - s->cropcap.bounds.left) + 1;
275 break;
276 default:
277 break;
278 }
183 279
184 err += sn9c102_write_reg(cam, h_start, 0x12); 280 err += sn9c102_write_reg(cam, h_start, 0x12);
185 err += sn9c102_write_reg(cam, v_start, 0x13); 281 err += sn9c102_write_reg(cam, v_start, 0x13);
@@ -194,24 +290,30 @@ static int mi0360_set_pix_format(struct sn9c102_device* cam,
194 struct sn9c102_sensor* s = sn9c102_get_sensor(cam); 290 struct sn9c102_sensor* s = sn9c102_get_sensor(cam);
195 int err = 0; 291 int err = 0;
196 292
197 if (pix->pixelformat == V4L2_PIX_FMT_SN9C10X) { 293 if (pix->pixelformat == V4L2_PIX_FMT_SBGGR8) {
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);
201 } else {
202 err += sn9c102_i2c_try_raw_write(cam, s, 4, s->i2c_slave_id, 294 err += sn9c102_i2c_try_raw_write(cam, s, 4, s->i2c_slave_id,
203 0x0a, 0x00, 0x05, 0, 0); 295 0x0a, 0x00, 0x05, 0, 0);
204 err += sn9c102_write_reg(cam, 0x60, 0x19); 296 err += sn9c102_write_reg(cam, 0x60, 0x19);
297 if (sn9c102_get_bridge(cam) == BRIDGE_SN9C105 ||
298 sn9c102_get_bridge(cam) == BRIDGE_SN9C120)
299 err += sn9c102_write_reg(cam, 0xa6, 0x17);
300 } else {
301 err += sn9c102_i2c_try_raw_write(cam, s, 4, s->i2c_slave_id,
302 0x0a, 0x00, 0x02, 0, 0);
303 err += sn9c102_write_reg(cam, 0x20, 0x19);
304 if (sn9c102_get_bridge(cam) == BRIDGE_SN9C105 ||
305 sn9c102_get_bridge(cam) == BRIDGE_SN9C120)
306 err += sn9c102_write_reg(cam, 0xa2, 0x17);
205 } 307 }
206 308
207 return err; 309 return err;
208} 310}
209 311
210 312
211static struct sn9c102_sensor mi0360 = { 313static const struct sn9c102_sensor mi0360 = {
212 .name = "MI-0360", 314 .name = "MI-0360",
213 .maintainer = "Luca Risolia <luca.risolia@studio.unibo.it>", 315 .maintainer = "Luca Risolia <luca.risolia@studio.unibo.it>",
214 .supported_bridge = BRIDGE_SN9C103, 316 .supported_bridge = BRIDGE_SN9C103 | BRIDGE_SN9C105 | BRIDGE_SN9C120,
215 .frequency = SN9C102_I2C_100KHZ, 317 .frequency = SN9C102_I2C_100KHZ,
216 .interface = SN9C102_I2C_2WIRES, 318 .interface = SN9C102_I2C_2WIRES,
217 .i2c_slave_id = 0x5d, 319 .i2c_slave_id = 0x5d,
@@ -317,19 +419,31 @@ static struct sn9c102_sensor mi0360 = {
317 419
318int sn9c102_probe_mi0360(struct sn9c102_device* cam) 420int sn9c102_probe_mi0360(struct sn9c102_device* cam)
319{ 421{
320 u8 data[5+1];
321 int err;
322 422
323 err = sn9c102_write_const_regs(cam, {0x01, 0x01}, {0x00, 0x01}, 423 u8 data[2];
324 {0x28, 0x17}); 424
325 if (err) 425 switch (sn9c102_get_bridge(cam)) {
326 return -EIO; 426 case BRIDGE_SN9C103:
427 if (sn9c102_write_const_regs(cam, {0x01, 0x01}, {0x00, 0x01},
428 {0x28, 0x17}))
429 return -EIO;
430 break;
431 case BRIDGE_SN9C105:
432 case BRIDGE_SN9C120:
433 if (sn9c102_write_const_regs(cam, {0x01, 0xf1}, {0x00, 0xf1},
434 {0x01, 0x01}, {0x00, 0x01},
435 {0x28, 0x17}))
436 return -EIO;
437 break;
438 default:
439 break;
440 }
327 441
328 if (sn9c102_i2c_try_raw_read(cam, &mi0360, mi0360.i2c_slave_id, 0x00, 442 if (sn9c102_i2c_try_raw_read(cam, &mi0360, mi0360.i2c_slave_id, 0x00,
329 2+1, data) < 0) 443 2, data) < 0)
330 return -EIO; 444 return -EIO;
331 445
332 if (data[2] != 0x82 || data[3] != 0x43) 446 if (data[0] != 0x82 || data[1] != 0x43)
333 return -ENODEV; 447 return -ENODEV;
334 448
335 sn9c102_attach_sensor(cam, &mi0360); 449 sn9c102_attach_sensor(cam, &mi0360);