This source file includes following definitions.
- em28xx_initialize_mt9m111
- em28xx_initialize_mt9m001
- em28xx_probe_sensor_micron
- em28xx_probe_sensor_omnivision
- em28xx_detect_sensor
- em28xx_init_camera
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 #include "em28xx.h"
19
20 #include <linux/i2c.h>
21 #include <linux/usb.h>
22 #include <media/i2c/mt9v011.h>
23 #include <media/v4l2-common.h>
24
25
26 static unsigned short micron_sensor_addrs[] = {
27 0xb8 >> 1,
28 0xba >> 1,
29 0x90 >> 1,
30 I2C_CLIENT_END
31 };
32
33
34 static unsigned short omnivision_sensor_addrs[] = {
35 0x42 >> 1,
36 0x60 >> 1,
37 I2C_CLIENT_END
38 };
39
40
41 static int em28xx_initialize_mt9m111(struct em28xx *dev)
42 {
43 int i;
44 unsigned char regs[][3] = {
45 { 0x0d, 0x00, 0x01, },
46 { 0x0d, 0x00, 0x00, },
47 { 0x0a, 0x00, 0x21, },
48 { 0x21, 0x04, 0x00, },
49 };
50
51 for (i = 0; i < ARRAY_SIZE(regs); i++)
52 i2c_master_send(&dev->i2c_client[dev->def_i2c_bus],
53 ®s[i][0], 3);
54
55
56
57 return 0;
58 }
59
60
61 static int em28xx_initialize_mt9m001(struct em28xx *dev)
62 {
63 int i;
64 unsigned char regs[][3] = {
65 { 0x0d, 0x00, 0x01, },
66 { 0x0d, 0x00, 0x00, },
67 { 0x04, 0x05, 0x00, },
68 { 0x03, 0x04, 0x00, },
69 { 0x20, 0x11, 0x00, },
70 { 0x06, 0x00, 0x10, },
71 { 0x2b, 0x00, 0x24, },
72 { 0x2e, 0x00, 0x24, },
73 { 0x35, 0x00, 0x24, },
74 { 0x2d, 0x00, 0x20, },
75 { 0x2c, 0x00, 0x20, },
76 { 0x09, 0x0a, 0xd4, },
77 { 0x35, 0x00, 0x57, },
78 };
79
80 for (i = 0; i < ARRAY_SIZE(regs); i++)
81 i2c_master_send(&dev->i2c_client[dev->def_i2c_bus],
82 ®s[i][0], 3);
83
84
85
86 return 0;
87 }
88
89
90
91
92 static int em28xx_probe_sensor_micron(struct em28xx *dev)
93 {
94 int ret, i;
95 char *name;
96 u16 id;
97
98 struct i2c_client *client = &dev->i2c_client[dev->def_i2c_bus];
99
100 dev->em28xx_sensor = EM28XX_NOSENSOR;
101 for (i = 0; micron_sensor_addrs[i] != I2C_CLIENT_END; i++) {
102 client->addr = micron_sensor_addrs[i];
103
104 ret = i2c_smbus_read_word_data(client, 0x00);
105 if (ret < 0) {
106 if (ret != -ENXIO)
107 dev_err(&dev->intf->dev,
108 "couldn't read from i2c device 0x%02x: error %i\n",
109 client->addr << 1, ret);
110 continue;
111 }
112 id = swab16(ret);
113
114 ret = i2c_smbus_read_word_data(client, 0xff);
115 if (ret < 0) {
116 dev_err(&dev->intf->dev,
117 "couldn't read from i2c device 0x%02x: error %i\n",
118 client->addr << 1, ret);
119 continue;
120 }
121
122 if (id != swab16(ret))
123 continue;
124
125 switch (id) {
126 case 0x1222:
127 name = "MT9V012";
128 break;
129 case 0x1229:
130 name = "MT9V112";
131 break;
132 case 0x1433:
133 name = "MT9M011";
134 break;
135 case 0x143a:
136 name = "MT9M111";
137 dev->em28xx_sensor = EM28XX_MT9M111;
138 break;
139 case 0x148c:
140 name = "MT9M112";
141 break;
142 case 0x1511:
143 name = "MT9D011";
144 break;
145 case 0x8232:
146 case 0x8243:
147 name = "MT9V011";
148 dev->em28xx_sensor = EM28XX_MT9V011;
149 break;
150 case 0x8431:
151 name = "MT9M001";
152 dev->em28xx_sensor = EM28XX_MT9M001;
153 break;
154 default:
155 dev_info(&dev->intf->dev,
156 "unknown Micron sensor detected: 0x%04x\n",
157 id);
158 return 0;
159 }
160
161 if (dev->em28xx_sensor == EM28XX_NOSENSOR)
162 dev_info(&dev->intf->dev,
163 "unsupported sensor detected: %s\n", name);
164 else
165 dev_info(&dev->intf->dev,
166 "sensor %s detected\n", name);
167
168 return 0;
169 }
170
171 return -ENODEV;
172 }
173
174
175
176
177 static int em28xx_probe_sensor_omnivision(struct em28xx *dev)
178 {
179 int ret, i;
180 char *name;
181 u8 reg;
182 u16 id;
183 struct i2c_client *client = &dev->i2c_client[dev->def_i2c_bus];
184
185 dev->em28xx_sensor = EM28XX_NOSENSOR;
186
187
188
189
190 for (i = 0; omnivision_sensor_addrs[i] != I2C_CLIENT_END; i++) {
191 client->addr = omnivision_sensor_addrs[i];
192
193 reg = 0x1c;
194 ret = i2c_smbus_read_byte_data(client, reg);
195 if (ret < 0) {
196 if (ret != -ENXIO)
197 dev_err(&dev->intf->dev,
198 "couldn't read from i2c device 0x%02x: error %i\n",
199 client->addr << 1, ret);
200 continue;
201 }
202 id = ret << 8;
203 reg = 0x1d;
204 ret = i2c_smbus_read_byte_data(client, reg);
205 if (ret < 0) {
206 dev_err(&dev->intf->dev,
207 "couldn't read from i2c device 0x%02x: error %i\n",
208 client->addr << 1, ret);
209 continue;
210 }
211 id += ret;
212
213 if (id != 0x7fa2)
214 continue;
215
216 reg = 0x0a;
217 ret = i2c_smbus_read_byte_data(client, reg);
218 if (ret < 0) {
219 dev_err(&dev->intf->dev,
220 "couldn't read from i2c device 0x%02x: error %i\n",
221 client->addr << 1, ret);
222 continue;
223 }
224 id = ret << 8;
225 reg = 0x0b;
226 ret = i2c_smbus_read_byte_data(client, reg);
227 if (ret < 0) {
228 dev_err(&dev->intf->dev,
229 "couldn't read from i2c device 0x%02x: error %i\n",
230 client->addr << 1, ret);
231 continue;
232 }
233 id += ret;
234
235 switch (id) {
236 case 0x2642:
237 name = "OV2640";
238 dev->em28xx_sensor = EM28XX_OV2640;
239 break;
240 case 0x7648:
241 name = "OV7648";
242 break;
243 case 0x7660:
244 name = "OV7660";
245 break;
246 case 0x7673:
247 name = "OV7670";
248 break;
249 case 0x7720:
250 name = "OV7720";
251 break;
252 case 0x7721:
253 name = "OV7725";
254 break;
255 case 0x9648:
256 case 0x9649:
257 name = "OV9640";
258 break;
259 case 0x9650:
260 case 0x9652:
261 name = "OV9650";
262 break;
263 case 0x9656:
264 case 0x9657:
265 name = "OV9655";
266 break;
267 default:
268 dev_info(&dev->intf->dev,
269 "unknown OmniVision sensor detected: 0x%04x\n",
270 id);
271 return 0;
272 }
273
274 if (dev->em28xx_sensor == EM28XX_NOSENSOR)
275 dev_info(&dev->intf->dev,
276 "unsupported sensor detected: %s\n", name);
277 else
278 dev_info(&dev->intf->dev,
279 "sensor %s detected\n", name);
280
281 return 0;
282 }
283
284 return -ENODEV;
285 }
286
287 int em28xx_detect_sensor(struct em28xx *dev)
288 {
289 int ret;
290
291 ret = em28xx_probe_sensor_micron(dev);
292
293 if (dev->em28xx_sensor == EM28XX_NOSENSOR && ret < 0)
294 ret = em28xx_probe_sensor_omnivision(dev);
295
296
297
298
299
300
301 if (dev->em28xx_sensor == EM28XX_NOSENSOR && ret < 0) {
302 dev_info(&dev->intf->dev,
303 "No sensor detected\n");
304 return -ENODEV;
305 }
306
307 return 0;
308 }
309
310 int em28xx_init_camera(struct em28xx *dev)
311 {
312 struct i2c_client *client = &dev->i2c_client[dev->def_i2c_bus];
313 struct i2c_adapter *adap = &dev->i2c_adap[dev->def_i2c_bus];
314 struct em28xx_v4l2 *v4l2 = dev->v4l2;
315
316 switch (dev->em28xx_sensor) {
317 case EM28XX_MT9V011:
318 {
319 struct mt9v011_platform_data pdata;
320 struct i2c_board_info mt9v011_info = {
321 .type = "mt9v011",
322 .addr = client->addr,
323 .platform_data = &pdata,
324 };
325
326 v4l2->sensor_xres = 640;
327 v4l2->sensor_yres = 480;
328
329
330
331
332
333
334
335
336
337
338 dev->board.xclk = EM28XX_XCLK_FREQUENCY_4_3MHZ;
339 em28xx_write_reg(dev, EM28XX_R0F_XCLK, dev->board.xclk);
340 v4l2->sensor_xtal = 4300000;
341 pdata.xtal = v4l2->sensor_xtal;
342 if (NULL ==
343 v4l2_i2c_new_subdev_board(&v4l2->v4l2_dev, adap,
344 &mt9v011_info, NULL))
345 return -ENODEV;
346 v4l2->vinmode = EM28XX_VINMODE_RGB8_GRBG;
347 v4l2->vinctl = 0x00;
348
349 break;
350 }
351 case EM28XX_MT9M001:
352 v4l2->sensor_xres = 1280;
353 v4l2->sensor_yres = 1024;
354
355 em28xx_initialize_mt9m001(dev);
356
357 v4l2->vinmode = EM28XX_VINMODE_RGB8_BGGR;
358 v4l2->vinctl = 0x00;
359
360 break;
361 case EM28XX_MT9M111:
362 v4l2->sensor_xres = 640;
363 v4l2->sensor_yres = 512;
364
365 dev->board.xclk = EM28XX_XCLK_FREQUENCY_48MHZ;
366 em28xx_write_reg(dev, EM28XX_R0F_XCLK, dev->board.xclk);
367 em28xx_initialize_mt9m111(dev);
368
369 v4l2->vinmode = EM28XX_VINMODE_YUV422_UYVY;
370 v4l2->vinctl = 0x00;
371
372 break;
373 case EM28XX_OV2640:
374 {
375 struct v4l2_subdev *subdev;
376 struct i2c_board_info ov2640_info = {
377 .type = "ov2640",
378 .flags = I2C_CLIENT_SCCB,
379 .addr = client->addr,
380 };
381 struct v4l2_subdev_format format = {
382 .which = V4L2_SUBDEV_FORMAT_ACTIVE,
383 };
384
385
386
387
388
389
390
391
392
393 v4l2->sensor_xres = 640;
394 v4l2->sensor_yres = 480;
395
396 subdev =
397 v4l2_i2c_new_subdev_board(&v4l2->v4l2_dev, adap,
398 &ov2640_info, NULL);
399 if (!subdev)
400 return -ENODEV;
401
402 format.format.code = MEDIA_BUS_FMT_YUYV8_2X8;
403 format.format.width = 640;
404 format.format.height = 480;
405 v4l2_subdev_call(subdev, pad, set_fmt, NULL, &format);
406
407
408 dev->board.xclk = EM28XX_XCLK_FREQUENCY_24MHZ;
409 em28xx_write_reg(dev, EM28XX_R0F_XCLK, dev->board.xclk);
410 v4l2->vinmode = EM28XX_VINMODE_YUV422_YUYV;
411 v4l2->vinctl = 0x00;
412
413 break;
414 }
415 case EM28XX_NOSENSOR:
416 default:
417 return -EINVAL;
418 }
419
420 return 0;
421 }
422 EXPORT_SYMBOL_GPL(em28xx_init_camera);