blob: ee0fe1f1307013187a60206d9cafeb56e9fc116e [file] [log] [blame]
Frank Schaefer855ff382013-03-27 17:06:31 -03001/*
2 em28xx-camera.c - driver for Empia EM25xx/27xx/28xx USB video capture devices
3
4 Copyright (C) 2009 Mauro Carvalho Chehab <mchehab@infradead.org>
5 Copyright (C) 2013 Frank Schäfer <fschaefer.oss@googlemail.com>
6
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.
11
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.
16
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*/
21
Mauro Carvalho Chehab8314d402016-10-12 07:26:47 -030022#include "em28xx.h"
23
Frank Schaefer855ff382013-03-27 17:06:31 -030024#include <linux/i2c.h>
Mauro Carvalho Chehabce8591f2016-10-20 08:42:03 -020025#include <linux/usb.h>
Mauro Carvalho Chehabb5dcee22015-11-10 12:01:44 -020026#include <media/i2c/mt9v011.h>
Frank Schaefer855ff382013-03-27 17:06:31 -030027#include <media/v4l2-common.h>
28
Frank Schaefer176013b2013-03-27 17:06:32 -030029/* Possible i2c addresses of Micron sensors */
30static unsigned short micron_sensor_addrs[] = {
31 0xb8 >> 1, /* MT9V111, MT9V403 */
32 0xba >> 1, /* MT9M001/011/111/112, MT9V011/012/112, MT9D011 */
33 0x90 >> 1, /* MT9V012/112, MT9D011 (alternative address) */
34 I2C_CLIENT_END
35};
36
Frank Schaeferbde03682013-03-27 17:06:34 -030037/* Possible i2c addresses of Omnivision sensors */
38static unsigned short omnivision_sensor_addrs[] = {
39 0x42 >> 1, /* OV7725, OV7670/60/48 */
40 0x60 >> 1, /* OV2640, OV9650/53/55 */
41 I2C_CLIENT_END
42};
43
Frank Schaefer855ff382013-03-27 17:06:31 -030044/* FIXME: Should be replaced by a proper mt9m111 driver */
45static int em28xx_initialize_mt9m111(struct em28xx *dev)
46{
47 int i;
48 unsigned char regs[][3] = {
49 { 0x0d, 0x00, 0x01, }, /* reset and use defaults */
50 { 0x0d, 0x00, 0x00, },
51 { 0x0a, 0x00, 0x21, },
52 { 0x21, 0x04, 0x00, }, /* full readout speed, no row/col skipping */
53 };
54
55 for (i = 0; i < ARRAY_SIZE(regs); i++)
56 i2c_master_send(&dev->i2c_client[dev->def_i2c_bus],
57 &regs[i][0], 3);
58
Mauro Carvalho Chehab37ecc7b2016-01-27 07:07:24 -020059 /* FIXME: This won't be creating a sensor at the media graph */
60
Frank Schaefer855ff382013-03-27 17:06:31 -030061 return 0;
62}
63
Frank Schaefer855ff382013-03-27 17:06:31 -030064/* FIXME: Should be replaced by a proper mt9m001 driver */
65static int em28xx_initialize_mt9m001(struct em28xx *dev)
66{
67 int i;
68 unsigned char regs[][3] = {
69 { 0x0d, 0x00, 0x01, },
70 { 0x0d, 0x00, 0x00, },
71 { 0x04, 0x05, 0x00, }, /* hres = 1280 */
72 { 0x03, 0x04, 0x00, }, /* vres = 1024 */
73 { 0x20, 0x11, 0x00, },
74 { 0x06, 0x00, 0x10, },
75 { 0x2b, 0x00, 0x24, },
76 { 0x2e, 0x00, 0x24, },
77 { 0x35, 0x00, 0x24, },
78 { 0x2d, 0x00, 0x20, },
79 { 0x2c, 0x00, 0x20, },
80 { 0x09, 0x0a, 0xd4, },
81 { 0x35, 0x00, 0x57, },
82 };
83
84 for (i = 0; i < ARRAY_SIZE(regs); i++)
85 i2c_master_send(&dev->i2c_client[dev->def_i2c_bus],
86 &regs[i][0], 3);
87
Mauro Carvalho Chehab37ecc7b2016-01-27 07:07:24 -020088 /* FIXME: This won't be creating a sensor at the media graph */
89
Frank Schaefer855ff382013-03-27 17:06:31 -030090 return 0;
91}
92
Frank Schaefer855ff382013-03-27 17:06:31 -030093/*
Frank Schaefer0af0b252013-03-27 17:06:33 -030094 * Probes Micron sensors with 8 bit address and 16 bit register width
Frank Schaefer855ff382013-03-27 17:06:31 -030095 */
Frank Schaefer0af0b252013-03-27 17:06:33 -030096static int em28xx_probe_sensor_micron(struct em28xx *dev)
Frank Schaefer855ff382013-03-27 17:06:31 -030097{
Frank Schaefer176013b2013-03-27 17:06:32 -030098 int ret, i;
Frank Schaefer855ff382013-03-27 17:06:31 -030099 char *name;
Frank Schaefer855ff382013-03-27 17:06:31 -0300100 u16 id;
101
Frank Schaefer9e006952017-02-19 15:29:17 -0300102 struct i2c_client *client = &dev->i2c_client[dev->def_i2c_bus];
Frank Schaefer855ff382013-03-27 17:06:31 -0300103
Frank Schaefer176013b2013-03-27 17:06:32 -0300104 dev->em28xx_sensor = EM28XX_NOSENSOR;
Frank Schaefer176013b2013-03-27 17:06:32 -0300105 for (i = 0; micron_sensor_addrs[i] != I2C_CLIENT_END; i++) {
Frank Schaefer9e006952017-02-19 15:29:17 -0300106 client->addr = micron_sensor_addrs[i];
Frank Schaefer176013b2013-03-27 17:06:32 -0300107 /* Read chip ID from register 0x00 */
Frank Schaefer4d5844362017-04-16 14:41:52 -0300108 ret = i2c_smbus_read_word_data(client, 0x00); /* assumes LE */
Frank Schaefer176013b2013-03-27 17:06:32 -0300109 if (ret < 0) {
Frank Schaefercb497c72014-01-17 14:45:31 -0300110 if (ret != -ENXIO)
Mauro Carvalho Chehab29b05e22016-12-07 13:48:10 -0200111 dev_err(&dev->intf->dev,
Mauro Carvalho Chehabce8591f2016-10-20 08:42:03 -0200112 "couldn't read from i2c device 0x%02x: error %i\n",
Frank Schaefer9e006952017-02-19 15:29:17 -0300113 client->addr << 1, ret);
Frank Schaefer176013b2013-03-27 17:06:32 -0300114 continue;
115 }
Frank Schaefer4d5844362017-04-16 14:41:52 -0300116 id = swab16(ret); /* LE -> BE */
Frank Schaefer176013b2013-03-27 17:06:32 -0300117 /* Read chip ID from register 0xff */
Frank Schaefer4d5844362017-04-16 14:41:52 -0300118 ret = i2c_smbus_read_word_data(client, 0xff);
Frank Schaefer176013b2013-03-27 17:06:32 -0300119 if (ret < 0) {
Mauro Carvalho Chehab29b05e22016-12-07 13:48:10 -0200120 dev_err(&dev->intf->dev,
Mauro Carvalho Chehabce8591f2016-10-20 08:42:03 -0200121 "couldn't read from i2c device 0x%02x: error %i\n",
Frank Schaefer9e006952017-02-19 15:29:17 -0300122 client->addr << 1, ret);
Frank Schaefer176013b2013-03-27 17:06:32 -0300123 continue;
124 }
125 /* Validate chip ID to be sure we have a Micron device */
Frank Schaefer4d5844362017-04-16 14:41:52 -0300126 if (id != swab16(ret))
Frank Schaefer176013b2013-03-27 17:06:32 -0300127 continue;
128 /* Check chip ID */
Frank Schaefer176013b2013-03-27 17:06:32 -0300129 switch (id) {
130 case 0x1222:
131 name = "MT9V012"; /* MI370 */ /* 640x480 */
132 break;
133 case 0x1229:
134 name = "MT9V112"; /* 640x480 */
135 break;
136 case 0x1433:
137 name = "MT9M011"; /* 1280x1024 */
138 break;
139 case 0x143a: /* found in the ECS G200 */
140 name = "MT9M111"; /* MI1310 */ /* 1280x1024 */
141 dev->em28xx_sensor = EM28XX_MT9M111;
142 break;
143 case 0x148c:
144 name = "MT9M112"; /* MI1320 */ /* 1280x1024 */
145 break;
146 case 0x1511:
147 name = "MT9D011"; /* MI2010 */ /* 1600x1200 */
148 break;
149 case 0x8232:
150 case 0x8243: /* rev B */
151 name = "MT9V011"; /* MI360 */ /* 640x480 */
152 dev->em28xx_sensor = EM28XX_MT9V011;
153 break;
154 case 0x8431:
155 name = "MT9M001"; /* 1280x1024 */
156 dev->em28xx_sensor = EM28XX_MT9M001;
157 break;
158 default:
Mauro Carvalho Chehab29b05e22016-12-07 13:48:10 -0200159 dev_info(&dev->intf->dev,
Mauro Carvalho Chehabce8591f2016-10-20 08:42:03 -0200160 "unknown Micron sensor detected: 0x%04x\n", id);
Frank Schaefer0af0b252013-03-27 17:06:33 -0300161 return 0;
Frank Schaefer176013b2013-03-27 17:06:32 -0300162 }
163
164 if (dev->em28xx_sensor == EM28XX_NOSENSOR)
Mauro Carvalho Chehab29b05e22016-12-07 13:48:10 -0200165 dev_info(&dev->intf->dev,
Mauro Carvalho Chehabce8591f2016-10-20 08:42:03 -0200166 "unsupported sensor detected: %s\n", name);
Frank Schaefer176013b2013-03-27 17:06:32 -0300167 else
Mauro Carvalho Chehab29b05e22016-12-07 13:48:10 -0200168 dev_info(&dev->intf->dev,
Mauro Carvalho Chehabce8591f2016-10-20 08:42:03 -0200169 "sensor %s detected\n", name);
Frank Schaefer176013b2013-03-27 17:06:32 -0300170
Frank Schaefer176013b2013-03-27 17:06:32 -0300171 return 0;
Frank Schaefer855ff382013-03-27 17:06:31 -0300172 }
173
Frank Schaefer176013b2013-03-27 17:06:32 -0300174 return -ENODEV;
Frank Schaefer855ff382013-03-27 17:06:31 -0300175}
176
Frank Schaefer0af0b252013-03-27 17:06:33 -0300177/*
Frank Schaeferbde03682013-03-27 17:06:34 -0300178 * Probes Omnivision sensors with 8 bit address and register width
Frank Schaefer0af0b252013-03-27 17:06:33 -0300179 */
Frank Schaeferbde03682013-03-27 17:06:34 -0300180static int em28xx_probe_sensor_omnivision(struct em28xx *dev)
181{
182 int ret, i;
183 char *name;
184 u8 reg;
185 u16 id;
Frank Schaefer9e006952017-02-19 15:29:17 -0300186 struct i2c_client *client = &dev->i2c_client[dev->def_i2c_bus];
Frank Schaeferbde03682013-03-27 17:06:34 -0300187
188 dev->em28xx_sensor = EM28XX_NOSENSOR;
189 /* NOTE: these devices have the register auto incrementation disabled
190 * by default, so we have to use single byte reads ! */
191 for (i = 0; omnivision_sensor_addrs[i] != I2C_CLIENT_END; i++) {
Frank Schaefer9e006952017-02-19 15:29:17 -0300192 client->addr = omnivision_sensor_addrs[i];
Frank Schaeferbde03682013-03-27 17:06:34 -0300193 /* Read manufacturer ID from registers 0x1c-0x1d (BE) */
194 reg = 0x1c;
Frank Schaefer9e006952017-02-19 15:29:17 -0300195 ret = i2c_smbus_read_byte_data(client, reg);
Frank Schaeferbde03682013-03-27 17:06:34 -0300196 if (ret < 0) {
Frank Schaefercb497c72014-01-17 14:45:31 -0300197 if (ret != -ENXIO)
Mauro Carvalho Chehab29b05e22016-12-07 13:48:10 -0200198 dev_err(&dev->intf->dev,
Mauro Carvalho Chehabce8591f2016-10-20 08:42:03 -0200199 "couldn't read from i2c device 0x%02x: error %i\n",
Frank Schaefer9e006952017-02-19 15:29:17 -0300200 client->addr << 1, ret);
Frank Schaeferbde03682013-03-27 17:06:34 -0300201 continue;
202 }
203 id = ret << 8;
204 reg = 0x1d;
Frank Schaefer9e006952017-02-19 15:29:17 -0300205 ret = i2c_smbus_read_byte_data(client, reg);
Frank Schaeferbde03682013-03-27 17:06:34 -0300206 if (ret < 0) {
Mauro Carvalho Chehab29b05e22016-12-07 13:48:10 -0200207 dev_err(&dev->intf->dev,
Mauro Carvalho Chehabce8591f2016-10-20 08:42:03 -0200208 "couldn't read from i2c device 0x%02x: error %i\n",
Frank Schaefer9e006952017-02-19 15:29:17 -0300209 client->addr << 1, ret);
Frank Schaeferbde03682013-03-27 17:06:34 -0300210 continue;
211 }
212 id += ret;
213 /* Check manufacturer ID */
214 if (id != 0x7fa2)
215 continue;
216 /* Read product ID from registers 0x0a-0x0b (BE) */
217 reg = 0x0a;
Frank Schaefer9e006952017-02-19 15:29:17 -0300218 ret = i2c_smbus_read_byte_data(client, reg);
Frank Schaeferbde03682013-03-27 17:06:34 -0300219 if (ret < 0) {
Mauro Carvalho Chehab29b05e22016-12-07 13:48:10 -0200220 dev_err(&dev->intf->dev,
Mauro Carvalho Chehabce8591f2016-10-20 08:42:03 -0200221 "couldn't read from i2c device 0x%02x: error %i\n",
Frank Schaefer9e006952017-02-19 15:29:17 -0300222 client->addr << 1, ret);
Frank Schaeferbde03682013-03-27 17:06:34 -0300223 continue;
224 }
225 id = ret << 8;
226 reg = 0x0b;
Frank Schaefer9e006952017-02-19 15:29:17 -0300227 ret = i2c_smbus_read_byte_data(client, reg);
Frank Schaeferbde03682013-03-27 17:06:34 -0300228 if (ret < 0) {
Mauro Carvalho Chehab29b05e22016-12-07 13:48:10 -0200229 dev_err(&dev->intf->dev,
Mauro Carvalho Chehabce8591f2016-10-20 08:42:03 -0200230 "couldn't read from i2c device 0x%02x: error %i\n",
Frank Schaefer9e006952017-02-19 15:29:17 -0300231 client->addr << 1, ret);
Frank Schaeferbde03682013-03-27 17:06:34 -0300232 continue;
233 }
234 id += ret;
235 /* Check product ID */
236 switch (id) {
237 case 0x2642:
238 name = "OV2640";
Frank Schaefere4b71312013-03-27 17:06:36 -0300239 dev->em28xx_sensor = EM28XX_OV2640;
Frank Schaeferbde03682013-03-27 17:06:34 -0300240 break;
241 case 0x7648:
242 name = "OV7648";
243 break;
244 case 0x7660:
245 name = "OV7660";
246 break;
247 case 0x7673:
248 name = "OV7670";
249 break;
250 case 0x7720:
251 name = "OV7720";
252 break;
253 case 0x7721:
254 name = "OV7725";
255 break;
256 case 0x9648: /* Rev 2 */
257 case 0x9649: /* Rev 3 */
258 name = "OV9640";
259 break;
260 case 0x9650:
261 case 0x9652: /* OV9653 */
262 name = "OV9650";
263 break;
264 case 0x9656: /* Rev 4 */
265 case 0x9657: /* Rev 5 */
266 name = "OV9655";
267 break;
268 default:
Mauro Carvalho Chehab29b05e22016-12-07 13:48:10 -0200269 dev_info(&dev->intf->dev,
Mauro Carvalho Chehabce8591f2016-10-20 08:42:03 -0200270 "unknown OmniVision sensor detected: 0x%04x\n",
Mauro Carvalho Chehab2a96f602016-10-12 07:32:23 -0300271 id);
Frank Schaeferbde03682013-03-27 17:06:34 -0300272 return 0;
273 }
274
275 if (dev->em28xx_sensor == EM28XX_NOSENSOR)
Mauro Carvalho Chehab29b05e22016-12-07 13:48:10 -0200276 dev_info(&dev->intf->dev,
Mauro Carvalho Chehabce8591f2016-10-20 08:42:03 -0200277 "unsupported sensor detected: %s\n", name);
Frank Schaeferbde03682013-03-27 17:06:34 -0300278 else
Mauro Carvalho Chehab29b05e22016-12-07 13:48:10 -0200279 dev_info(&dev->intf->dev,
Mauro Carvalho Chehabce8591f2016-10-20 08:42:03 -0200280 "sensor %s detected\n", name);
Frank Schaeferbde03682013-03-27 17:06:34 -0300281
Frank Schaeferbde03682013-03-27 17:06:34 -0300282 return 0;
283 }
284
285 return -ENODEV;
286}
287
Frank Schaefer0af0b252013-03-27 17:06:33 -0300288int em28xx_detect_sensor(struct em28xx *dev)
289{
290 int ret;
291
292 ret = em28xx_probe_sensor_micron(dev);
Frank Schaeferbde03682013-03-27 17:06:34 -0300293
294 if (dev->em28xx_sensor == EM28XX_NOSENSOR && ret < 0)
295 ret = em28xx_probe_sensor_omnivision(dev);
296
Frank Schaefer52f1f232013-03-27 17:06:35 -0300297 /*
298 * NOTE: the Windows driver also probes i2c addresses
299 * 0x22 (Samsung ?) and 0x66 (Kodak ?)
300 */
301
Frank Schaefer0af0b252013-03-27 17:06:33 -0300302 if (dev->em28xx_sensor == EM28XX_NOSENSOR && ret < 0) {
Mauro Carvalho Chehab29b05e22016-12-07 13:48:10 -0200303 dev_info(&dev->intf->dev,
Mauro Carvalho Chehabce8591f2016-10-20 08:42:03 -0200304 "No sensor detected\n");
Frank Schaefer0af0b252013-03-27 17:06:33 -0300305 return -ENODEV;
306 }
307
308 return 0;
309}
310
Frank Schaefer855ff382013-03-27 17:06:31 -0300311int em28xx_init_camera(struct em28xx *dev)
312{
Guennadi Liakhovetskifc5d0f82013-08-28 10:28:28 -0300313 struct i2c_client *client = &dev->i2c_client[dev->def_i2c_bus];
314 struct i2c_adapter *adap = &dev->i2c_adap[dev->def_i2c_bus];
Frank Schaefer2c52a2f2014-03-24 16:33:11 -0300315 struct em28xx_v4l2 *v4l2 = dev->v4l2;
Guennadi Liakhovetskifc5d0f82013-08-28 10:28:28 -0300316
Frank Schaefer855ff382013-03-27 17:06:31 -0300317 switch (dev->em28xx_sensor) {
318 case EM28XX_MT9V011:
319 {
320 struct mt9v011_platform_data pdata;
321 struct i2c_board_info mt9v011_info = {
322 .type = "mt9v011",
Guennadi Liakhovetskifc5d0f82013-08-28 10:28:28 -0300323 .addr = client->addr,
Frank Schaefer855ff382013-03-27 17:06:31 -0300324 .platform_data = &pdata,
325 };
326
Frank Schaeferd7dc18d2014-03-24 16:33:19 -0300327 v4l2->sensor_xres = 640;
328 v4l2->sensor_yres = 480;
Frank Schaefer855ff382013-03-27 17:06:31 -0300329
330 /*
331 * FIXME: mt9v011 uses I2S speed as xtal clk - at least with
332 * the Silvercrest cam I have here for testing - for higher
333 * resolutions, a high clock cause horizontal artifacts, so we
334 * need to use a lower xclk frequency.
335 * Yet, it would be possible to adjust xclk depending on the
336 * desired resolution, since this affects directly the
337 * frame rate.
338 */
339 dev->board.xclk = EM28XX_XCLK_FREQUENCY_4_3MHZ;
340 em28xx_write_reg(dev, EM28XX_R0F_XCLK, dev->board.xclk);
Frank Schaeferd7dc18d2014-03-24 16:33:19 -0300341 v4l2->sensor_xtal = 4300000;
342 pdata.xtal = v4l2->sensor_xtal;
Frank Schaefer855ff382013-03-27 17:06:31 -0300343 if (NULL ==
Frank Schaefer50153892014-07-25 14:48:55 -0300344 v4l2_i2c_new_subdev_board(&v4l2->v4l2_dev, adap,
Frank Schaefer2437aeb2017-04-15 07:05:00 -0300345 &mt9v011_info, NULL))
346 return -ENODEV;
Frank Schaefer855ff382013-03-27 17:06:31 -0300347 /* probably means GRGB 16 bit bayer */
Frank Schaefer92972852014-03-24 16:33:15 -0300348 v4l2->vinmode = 0x0d;
349 v4l2->vinctl = 0x00;
Frank Schaefer855ff382013-03-27 17:06:31 -0300350
351 break;
352 }
353 case EM28XX_MT9M001:
Frank Schaeferd7dc18d2014-03-24 16:33:19 -0300354 v4l2->sensor_xres = 1280;
355 v4l2->sensor_yres = 1024;
Frank Schaefer855ff382013-03-27 17:06:31 -0300356
357 em28xx_initialize_mt9m001(dev);
358
359 /* probably means BGGR 16 bit bayer */
Frank Schaefer92972852014-03-24 16:33:15 -0300360 v4l2->vinmode = 0x0c;
361 v4l2->vinctl = 0x00;
Frank Schaefer855ff382013-03-27 17:06:31 -0300362
363 break;
364 case EM28XX_MT9M111:
Frank Schaeferd7dc18d2014-03-24 16:33:19 -0300365 v4l2->sensor_xres = 640;
366 v4l2->sensor_yres = 512;
Frank Schaefer855ff382013-03-27 17:06:31 -0300367
368 dev->board.xclk = EM28XX_XCLK_FREQUENCY_48MHZ;
369 em28xx_write_reg(dev, EM28XX_R0F_XCLK, dev->board.xclk);
370 em28xx_initialize_mt9m111(dev);
371
Frank Schaefer92972852014-03-24 16:33:15 -0300372 v4l2->vinmode = 0x0a;
373 v4l2->vinctl = 0x00;
Frank Schaefer855ff382013-03-27 17:06:31 -0300374
375 break;
Frank Schaefere4b71312013-03-27 17:06:36 -0300376 case EM28XX_OV2640:
377 {
378 struct v4l2_subdev *subdev;
379 struct i2c_board_info ov2640_info = {
380 .type = "ov2640",
381 .flags = I2C_CLIENT_SCCB,
Guennadi Liakhovetskifc5d0f82013-08-28 10:28:28 -0300382 .addr = client->addr,
Frank Schaefere4b71312013-03-27 17:06:36 -0300383 };
Hans Verkuilebf984b2015-04-09 04:05:59 -0300384 struct v4l2_subdev_format format = {
385 .which = V4L2_SUBDEV_FORMAT_ACTIVE,
386 };
Frank Schaefere4b71312013-03-27 17:06:36 -0300387
388 /*
389 * FIXME: sensor supports resolutions up to 1600x1200, but
390 * resolution setting/switching needs to be modified to
391 * - switch sensor output resolution (including further
392 * configuration changes)
393 * - adjust bridge xclk
394 * - disable 16 bit (12 bit) output formats on high resolutions
395 */
Frank Schaeferd7dc18d2014-03-24 16:33:19 -0300396 v4l2->sensor_xres = 640;
397 v4l2->sensor_yres = 480;
Frank Schaefere4b71312013-03-27 17:06:36 -0300398
399 subdev =
Frank Schaefer50153892014-07-25 14:48:55 -0300400 v4l2_i2c_new_subdev_board(&v4l2->v4l2_dev, adap,
Frank Schaefere4b71312013-03-27 17:06:36 -0300401 &ov2640_info, NULL);
Frank Schaefer2437aeb2017-04-15 07:05:00 -0300402 if (subdev == NULL)
403 return -ENODEV;
Frank Schaefere4b71312013-03-27 17:06:36 -0300404
Hans Verkuilebf984b2015-04-09 04:05:59 -0300405 format.format.code = MEDIA_BUS_FMT_YUYV8_2X8;
406 format.format.width = 640;
407 format.format.height = 480;
408 v4l2_subdev_call(subdev, pad, set_fmt, NULL, &format);
Frank Schaefere4b71312013-03-27 17:06:36 -0300409
410 /* NOTE: for UXGA=1600x1200 switch to 12MHz */
411 dev->board.xclk = EM28XX_XCLK_FREQUENCY_24MHZ;
412 em28xx_write_reg(dev, EM28XX_R0F_XCLK, dev->board.xclk);
Frank Schaefer92972852014-03-24 16:33:15 -0300413 v4l2->vinmode = 0x08;
414 v4l2->vinctl = 0x00;
Frank Schaefere4b71312013-03-27 17:06:36 -0300415
416 break;
417 }
Frank Schaefer855ff382013-03-27 17:06:31 -0300418 case EM28XX_NOSENSOR:
419 default:
Frank Schaefer2437aeb2017-04-15 07:05:00 -0300420 return -EINVAL;
Frank Schaefer855ff382013-03-27 17:06:31 -0300421 }
422
Frank Schaefer2437aeb2017-04-15 07:05:00 -0300423 return 0;
Frank Schaefer855ff382013-03-27 17:06:31 -0300424}
Mauro Carvalho Chehab01c28192013-12-22 13:27:02 -0300425EXPORT_SYMBOL_GPL(em28xx_init_camera);