blob: 89c890ba7dd61f843ec1bcb037f27318b5197b93 [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>
Frank Schaefere4b71312013-03-27 17:06:36 -030026#include <media/soc_camera.h>
Mauro Carvalho Chehabb5dcee22015-11-10 12:01:44 -020027#include <media/i2c/mt9v011.h>
Guennadi Liakhovetskifc5d0f82013-08-28 10:28:28 -030028#include <media/v4l2-clk.h>
Frank Schaefer855ff382013-03-27 17:06:31 -030029#include <media/v4l2-common.h>
30
Frank Schaefer176013b2013-03-27 17:06:32 -030031/* Possible i2c addresses of Micron sensors */
32static unsigned short micron_sensor_addrs[] = {
33 0xb8 >> 1, /* MT9V111, MT9V403 */
34 0xba >> 1, /* MT9M001/011/111/112, MT9V011/012/112, MT9D011 */
35 0x90 >> 1, /* MT9V012/112, MT9D011 (alternative address) */
36 I2C_CLIENT_END
37};
38
Frank Schaeferbde03682013-03-27 17:06:34 -030039/* Possible i2c addresses of Omnivision sensors */
40static unsigned short omnivision_sensor_addrs[] = {
41 0x42 >> 1, /* OV7725, OV7670/60/48 */
42 0x60 >> 1, /* OV2640, OV9650/53/55 */
43 I2C_CLIENT_END
44};
45
Frank Schaefere4b71312013-03-27 17:06:36 -030046static struct soc_camera_link camlink = {
47 .bus_id = 0,
48 .flags = 0,
49 .module_name = "em28xx",
Guennadi Liakhovetskibe353fa2013-10-21 06:28:06 -030050 .unbalanced_power = true,
Frank Schaefere4b71312013-03-27 17:06:36 -030051};
52
Frank Schaefer855ff382013-03-27 17:06:31 -030053/* FIXME: Should be replaced by a proper mt9m111 driver */
54static int em28xx_initialize_mt9m111(struct em28xx *dev)
55{
56 int i;
57 unsigned char regs[][3] = {
58 { 0x0d, 0x00, 0x01, }, /* reset and use defaults */
59 { 0x0d, 0x00, 0x00, },
60 { 0x0a, 0x00, 0x21, },
61 { 0x21, 0x04, 0x00, }, /* full readout speed, no row/col skipping */
62 };
63
64 for (i = 0; i < ARRAY_SIZE(regs); i++)
65 i2c_master_send(&dev->i2c_client[dev->def_i2c_bus],
66 &regs[i][0], 3);
67
Mauro Carvalho Chehab37ecc7b2016-01-27 07:07:24 -020068 /* FIXME: This won't be creating a sensor at the media graph */
69
Frank Schaefer855ff382013-03-27 17:06:31 -030070 return 0;
71}
72
Frank Schaefer855ff382013-03-27 17:06:31 -030073/* FIXME: Should be replaced by a proper mt9m001 driver */
74static int em28xx_initialize_mt9m001(struct em28xx *dev)
75{
76 int i;
77 unsigned char regs[][3] = {
78 { 0x0d, 0x00, 0x01, },
79 { 0x0d, 0x00, 0x00, },
80 { 0x04, 0x05, 0x00, }, /* hres = 1280 */
81 { 0x03, 0x04, 0x00, }, /* vres = 1024 */
82 { 0x20, 0x11, 0x00, },
83 { 0x06, 0x00, 0x10, },
84 { 0x2b, 0x00, 0x24, },
85 { 0x2e, 0x00, 0x24, },
86 { 0x35, 0x00, 0x24, },
87 { 0x2d, 0x00, 0x20, },
88 { 0x2c, 0x00, 0x20, },
89 { 0x09, 0x0a, 0xd4, },
90 { 0x35, 0x00, 0x57, },
91 };
92
93 for (i = 0; i < ARRAY_SIZE(regs); i++)
94 i2c_master_send(&dev->i2c_client[dev->def_i2c_bus],
95 &regs[i][0], 3);
96
Mauro Carvalho Chehab37ecc7b2016-01-27 07:07:24 -020097 /* FIXME: This won't be creating a sensor at the media graph */
98
Frank Schaefer855ff382013-03-27 17:06:31 -030099 return 0;
100}
101
Frank Schaefer855ff382013-03-27 17:06:31 -0300102/*
Frank Schaefer0af0b252013-03-27 17:06:33 -0300103 * Probes Micron sensors with 8 bit address and 16 bit register width
Frank Schaefer855ff382013-03-27 17:06:31 -0300104 */
Frank Schaefer0af0b252013-03-27 17:06:33 -0300105static int em28xx_probe_sensor_micron(struct em28xx *dev)
Frank Schaefer855ff382013-03-27 17:06:31 -0300106{
Frank Schaefer176013b2013-03-27 17:06:32 -0300107 int ret, i;
Frank Schaefer855ff382013-03-27 17:06:31 -0300108 char *name;
109 u8 reg;
110 __be16 id_be;
111 u16 id;
112
Frank Schaefer176013b2013-03-27 17:06:32 -0300113 struct i2c_client client = dev->i2c_client[dev->def_i2c_bus];
Frank Schaefer855ff382013-03-27 17:06:31 -0300114
Frank Schaefer176013b2013-03-27 17:06:32 -0300115 dev->em28xx_sensor = EM28XX_NOSENSOR;
Frank Schaefer176013b2013-03-27 17:06:32 -0300116 for (i = 0; micron_sensor_addrs[i] != I2C_CLIENT_END; i++) {
117 client.addr = micron_sensor_addrs[i];
118 /* NOTE: i2c_smbus_read_word_data() doesn't work with BE data */
119 /* Read chip ID from register 0x00 */
120 reg = 0x00;
121 ret = i2c_master_send(&client, &reg, 1);
122 if (ret < 0) {
Frank Schaefercb497c72014-01-17 14:45:31 -0300123 if (ret != -ENXIO)
Mauro Carvalho Chehab29b05e22016-12-07 13:48:10 -0200124 dev_err(&dev->intf->dev,
Mauro Carvalho Chehabce8591f2016-10-20 08:42:03 -0200125 "couldn't read from i2c device 0x%02x: error %i\n",
Mauro Carvalho Chehab2a96f602016-10-12 07:32:23 -0300126 client.addr << 1, ret);
Frank Schaefer176013b2013-03-27 17:06:32 -0300127 continue;
128 }
129 ret = i2c_master_recv(&client, (u8 *)&id_be, 2);
130 if (ret < 0) {
Mauro Carvalho Chehab29b05e22016-12-07 13:48:10 -0200131 dev_err(&dev->intf->dev,
Mauro Carvalho Chehabce8591f2016-10-20 08:42:03 -0200132 "couldn't read from i2c device 0x%02x: error %i\n",
133 client.addr << 1, ret);
Frank Schaefer176013b2013-03-27 17:06:32 -0300134 continue;
135 }
136 id = be16_to_cpu(id_be);
137 /* Read chip ID from register 0xff */
138 reg = 0xff;
139 ret = i2c_master_send(&client, &reg, 1);
140 if (ret < 0) {
Mauro Carvalho Chehab29b05e22016-12-07 13:48:10 -0200141 dev_err(&dev->intf->dev,
Mauro Carvalho Chehabce8591f2016-10-20 08:42:03 -0200142 "couldn't read from i2c device 0x%02x: error %i\n",
143 client.addr << 1, ret);
Frank Schaefer176013b2013-03-27 17:06:32 -0300144 continue;
145 }
146 ret = i2c_master_recv(&client, (u8 *)&id_be, 2);
147 if (ret < 0) {
Mauro Carvalho Chehab29b05e22016-12-07 13:48:10 -0200148 dev_err(&dev->intf->dev,
Mauro Carvalho Chehabce8591f2016-10-20 08:42:03 -0200149 "couldn't read from i2c device 0x%02x: error %i\n",
150 client.addr << 1, ret);
Frank Schaefer176013b2013-03-27 17:06:32 -0300151 continue;
152 }
153 /* Validate chip ID to be sure we have a Micron device */
154 if (id != be16_to_cpu(id_be))
155 continue;
156 /* Check chip ID */
157 id = be16_to_cpu(id_be);
158 switch (id) {
159 case 0x1222:
160 name = "MT9V012"; /* MI370 */ /* 640x480 */
161 break;
162 case 0x1229:
163 name = "MT9V112"; /* 640x480 */
164 break;
165 case 0x1433:
166 name = "MT9M011"; /* 1280x1024 */
167 break;
168 case 0x143a: /* found in the ECS G200 */
169 name = "MT9M111"; /* MI1310 */ /* 1280x1024 */
170 dev->em28xx_sensor = EM28XX_MT9M111;
171 break;
172 case 0x148c:
173 name = "MT9M112"; /* MI1320 */ /* 1280x1024 */
174 break;
175 case 0x1511:
176 name = "MT9D011"; /* MI2010 */ /* 1600x1200 */
177 break;
178 case 0x8232:
179 case 0x8243: /* rev B */
180 name = "MT9V011"; /* MI360 */ /* 640x480 */
181 dev->em28xx_sensor = EM28XX_MT9V011;
182 break;
183 case 0x8431:
184 name = "MT9M001"; /* 1280x1024 */
185 dev->em28xx_sensor = EM28XX_MT9M001;
186 break;
187 default:
Mauro Carvalho Chehab29b05e22016-12-07 13:48:10 -0200188 dev_info(&dev->intf->dev,
Mauro Carvalho Chehabce8591f2016-10-20 08:42:03 -0200189 "unknown Micron sensor detected: 0x%04x\n", id);
Frank Schaefer0af0b252013-03-27 17:06:33 -0300190 return 0;
Frank Schaefer176013b2013-03-27 17:06:32 -0300191 }
192
193 if (dev->em28xx_sensor == EM28XX_NOSENSOR)
Mauro Carvalho Chehab29b05e22016-12-07 13:48:10 -0200194 dev_info(&dev->intf->dev,
Mauro Carvalho Chehabce8591f2016-10-20 08:42:03 -0200195 "unsupported sensor detected: %s\n", name);
Frank Schaefer176013b2013-03-27 17:06:32 -0300196 else
Mauro Carvalho Chehab29b05e22016-12-07 13:48:10 -0200197 dev_info(&dev->intf->dev,
Mauro Carvalho Chehabce8591f2016-10-20 08:42:03 -0200198 "sensor %s detected\n", name);
Frank Schaefer176013b2013-03-27 17:06:32 -0300199
200 dev->i2c_client[dev->def_i2c_bus].addr = client.addr;
201 return 0;
Frank Schaefer855ff382013-03-27 17:06:31 -0300202 }
203
Frank Schaefer176013b2013-03-27 17:06:32 -0300204 return -ENODEV;
Frank Schaefer855ff382013-03-27 17:06:31 -0300205}
206
Frank Schaefer0af0b252013-03-27 17:06:33 -0300207/*
Frank Schaeferbde03682013-03-27 17:06:34 -0300208 * Probes Omnivision sensors with 8 bit address and register width
Frank Schaefer0af0b252013-03-27 17:06:33 -0300209 */
Frank Schaeferbde03682013-03-27 17:06:34 -0300210static int em28xx_probe_sensor_omnivision(struct em28xx *dev)
211{
212 int ret, i;
213 char *name;
214 u8 reg;
215 u16 id;
216 struct i2c_client client = dev->i2c_client[dev->def_i2c_bus];
217
218 dev->em28xx_sensor = EM28XX_NOSENSOR;
219 /* NOTE: these devices have the register auto incrementation disabled
220 * by default, so we have to use single byte reads ! */
221 for (i = 0; omnivision_sensor_addrs[i] != I2C_CLIENT_END; i++) {
222 client.addr = omnivision_sensor_addrs[i];
223 /* Read manufacturer ID from registers 0x1c-0x1d (BE) */
224 reg = 0x1c;
225 ret = i2c_smbus_read_byte_data(&client, reg);
226 if (ret < 0) {
Frank Schaefercb497c72014-01-17 14:45:31 -0300227 if (ret != -ENXIO)
Mauro Carvalho Chehab29b05e22016-12-07 13:48:10 -0200228 dev_err(&dev->intf->dev,
Mauro Carvalho Chehabce8591f2016-10-20 08:42:03 -0200229 "couldn't read from i2c device 0x%02x: error %i\n",
230 client.addr << 1, ret);
Frank Schaeferbde03682013-03-27 17:06:34 -0300231 continue;
232 }
233 id = ret << 8;
234 reg = 0x1d;
235 ret = i2c_smbus_read_byte_data(&client, reg);
236 if (ret < 0) {
Mauro Carvalho Chehab29b05e22016-12-07 13:48:10 -0200237 dev_err(&dev->intf->dev,
Mauro Carvalho Chehabce8591f2016-10-20 08:42:03 -0200238 "couldn't read from i2c device 0x%02x: error %i\n",
239 client.addr << 1, ret);
Frank Schaeferbde03682013-03-27 17:06:34 -0300240 continue;
241 }
242 id += ret;
243 /* Check manufacturer ID */
244 if (id != 0x7fa2)
245 continue;
246 /* Read product ID from registers 0x0a-0x0b (BE) */
247 reg = 0x0a;
248 ret = i2c_smbus_read_byte_data(&client, reg);
249 if (ret < 0) {
Mauro Carvalho Chehab29b05e22016-12-07 13:48:10 -0200250 dev_err(&dev->intf->dev,
Mauro Carvalho Chehabce8591f2016-10-20 08:42:03 -0200251 "couldn't read from i2c device 0x%02x: error %i\n",
252 client.addr << 1, ret);
Frank Schaeferbde03682013-03-27 17:06:34 -0300253 continue;
254 }
255 id = ret << 8;
256 reg = 0x0b;
257 ret = i2c_smbus_read_byte_data(&client, reg);
258 if (ret < 0) {
Mauro Carvalho Chehab29b05e22016-12-07 13:48:10 -0200259 dev_err(&dev->intf->dev,
Mauro Carvalho Chehabce8591f2016-10-20 08:42:03 -0200260 "couldn't read from i2c device 0x%02x: error %i\n",
261 client.addr << 1, ret);
Frank Schaeferbde03682013-03-27 17:06:34 -0300262 continue;
263 }
264 id += ret;
265 /* Check product ID */
266 switch (id) {
267 case 0x2642:
268 name = "OV2640";
Frank Schaefere4b71312013-03-27 17:06:36 -0300269 dev->em28xx_sensor = EM28XX_OV2640;
Frank Schaeferbde03682013-03-27 17:06:34 -0300270 break;
271 case 0x7648:
272 name = "OV7648";
273 break;
274 case 0x7660:
275 name = "OV7660";
276 break;
277 case 0x7673:
278 name = "OV7670";
279 break;
280 case 0x7720:
281 name = "OV7720";
282 break;
283 case 0x7721:
284 name = "OV7725";
285 break;
286 case 0x9648: /* Rev 2 */
287 case 0x9649: /* Rev 3 */
288 name = "OV9640";
289 break;
290 case 0x9650:
291 case 0x9652: /* OV9653 */
292 name = "OV9650";
293 break;
294 case 0x9656: /* Rev 4 */
295 case 0x9657: /* Rev 5 */
296 name = "OV9655";
297 break;
298 default:
Mauro Carvalho Chehab29b05e22016-12-07 13:48:10 -0200299 dev_info(&dev->intf->dev,
Mauro Carvalho Chehabce8591f2016-10-20 08:42:03 -0200300 "unknown OmniVision sensor detected: 0x%04x\n",
Mauro Carvalho Chehab2a96f602016-10-12 07:32:23 -0300301 id);
Frank Schaeferbde03682013-03-27 17:06:34 -0300302 return 0;
303 }
304
305 if (dev->em28xx_sensor == EM28XX_NOSENSOR)
Mauro Carvalho Chehab29b05e22016-12-07 13:48:10 -0200306 dev_info(&dev->intf->dev,
Mauro Carvalho Chehabce8591f2016-10-20 08:42:03 -0200307 "unsupported sensor detected: %s\n", name);
Frank Schaeferbde03682013-03-27 17:06:34 -0300308 else
Mauro Carvalho Chehab29b05e22016-12-07 13:48:10 -0200309 dev_info(&dev->intf->dev,
Mauro Carvalho Chehabce8591f2016-10-20 08:42:03 -0200310 "sensor %s detected\n", name);
Frank Schaeferbde03682013-03-27 17:06:34 -0300311
312 dev->i2c_client[dev->def_i2c_bus].addr = client.addr;
313 return 0;
314 }
315
316 return -ENODEV;
317}
318
Frank Schaefer0af0b252013-03-27 17:06:33 -0300319int em28xx_detect_sensor(struct em28xx *dev)
320{
321 int ret;
322
323 ret = em28xx_probe_sensor_micron(dev);
Frank Schaeferbde03682013-03-27 17:06:34 -0300324
325 if (dev->em28xx_sensor == EM28XX_NOSENSOR && ret < 0)
326 ret = em28xx_probe_sensor_omnivision(dev);
327
Frank Schaefer52f1f232013-03-27 17:06:35 -0300328 /*
329 * NOTE: the Windows driver also probes i2c addresses
330 * 0x22 (Samsung ?) and 0x66 (Kodak ?)
331 */
332
Frank Schaefer0af0b252013-03-27 17:06:33 -0300333 if (dev->em28xx_sensor == EM28XX_NOSENSOR && ret < 0) {
Mauro Carvalho Chehab29b05e22016-12-07 13:48:10 -0200334 dev_info(&dev->intf->dev,
Mauro Carvalho Chehabce8591f2016-10-20 08:42:03 -0200335 "No sensor detected\n");
Frank Schaefer0af0b252013-03-27 17:06:33 -0300336 return -ENODEV;
337 }
338
339 return 0;
340}
341
Frank Schaefer855ff382013-03-27 17:06:31 -0300342int em28xx_init_camera(struct em28xx *dev)
343{
Josh Wu3d830782015-10-28 07:48:54 -0200344 char clk_name[V4L2_CLK_NAME_SIZE];
Guennadi Liakhovetskifc5d0f82013-08-28 10:28:28 -0300345 struct i2c_client *client = &dev->i2c_client[dev->def_i2c_bus];
346 struct i2c_adapter *adap = &dev->i2c_adap[dev->def_i2c_bus];
Frank Schaefer2c52a2f2014-03-24 16:33:11 -0300347 struct em28xx_v4l2 *v4l2 = dev->v4l2;
Guennadi Liakhovetskifc5d0f82013-08-28 10:28:28 -0300348 int ret = 0;
349
350 v4l2_clk_name_i2c(clk_name, sizeof(clk_name),
351 i2c_adapter_id(adap), client->addr);
Guennadi Liakhovetskia37462b2015-01-31 20:21:32 -0300352 v4l2->clk = v4l2_clk_register_fixed(clk_name, -EINVAL);
Frank Schaefer2c52a2f2014-03-24 16:33:11 -0300353 if (IS_ERR(v4l2->clk))
354 return PTR_ERR(v4l2->clk);
Guennadi Liakhovetskifc5d0f82013-08-28 10:28:28 -0300355
Frank Schaefer855ff382013-03-27 17:06:31 -0300356 switch (dev->em28xx_sensor) {
357 case EM28XX_MT9V011:
358 {
359 struct mt9v011_platform_data pdata;
360 struct i2c_board_info mt9v011_info = {
361 .type = "mt9v011",
Guennadi Liakhovetskifc5d0f82013-08-28 10:28:28 -0300362 .addr = client->addr,
Frank Schaefer855ff382013-03-27 17:06:31 -0300363 .platform_data = &pdata,
364 };
365
Frank Schaeferd7dc18d2014-03-24 16:33:19 -0300366 v4l2->sensor_xres = 640;
367 v4l2->sensor_yres = 480;
Frank Schaefer855ff382013-03-27 17:06:31 -0300368
369 /*
370 * FIXME: mt9v011 uses I2S speed as xtal clk - at least with
371 * the Silvercrest cam I have here for testing - for higher
372 * resolutions, a high clock cause horizontal artifacts, so we
373 * need to use a lower xclk frequency.
374 * Yet, it would be possible to adjust xclk depending on the
375 * desired resolution, since this affects directly the
376 * frame rate.
377 */
378 dev->board.xclk = EM28XX_XCLK_FREQUENCY_4_3MHZ;
379 em28xx_write_reg(dev, EM28XX_R0F_XCLK, dev->board.xclk);
Frank Schaeferd7dc18d2014-03-24 16:33:19 -0300380 v4l2->sensor_xtal = 4300000;
381 pdata.xtal = v4l2->sensor_xtal;
Frank Schaefer855ff382013-03-27 17:06:31 -0300382 if (NULL ==
Frank Schaefer50153892014-07-25 14:48:55 -0300383 v4l2_i2c_new_subdev_board(&v4l2->v4l2_dev, adap,
Guennadi Liakhovetskifc5d0f82013-08-28 10:28:28 -0300384 &mt9v011_info, NULL)) {
385 ret = -ENODEV;
386 break;
387 }
Frank Schaefer855ff382013-03-27 17:06:31 -0300388 /* probably means GRGB 16 bit bayer */
Frank Schaefer92972852014-03-24 16:33:15 -0300389 v4l2->vinmode = 0x0d;
390 v4l2->vinctl = 0x00;
Frank Schaefer855ff382013-03-27 17:06:31 -0300391
392 break;
393 }
394 case EM28XX_MT9M001:
Frank Schaeferd7dc18d2014-03-24 16:33:19 -0300395 v4l2->sensor_xres = 1280;
396 v4l2->sensor_yres = 1024;
Frank Schaefer855ff382013-03-27 17:06:31 -0300397
398 em28xx_initialize_mt9m001(dev);
399
400 /* probably means BGGR 16 bit bayer */
Frank Schaefer92972852014-03-24 16:33:15 -0300401 v4l2->vinmode = 0x0c;
402 v4l2->vinctl = 0x00;
Frank Schaefer855ff382013-03-27 17:06:31 -0300403
404 break;
405 case EM28XX_MT9M111:
Frank Schaeferd7dc18d2014-03-24 16:33:19 -0300406 v4l2->sensor_xres = 640;
407 v4l2->sensor_yres = 512;
Frank Schaefer855ff382013-03-27 17:06:31 -0300408
409 dev->board.xclk = EM28XX_XCLK_FREQUENCY_48MHZ;
410 em28xx_write_reg(dev, EM28XX_R0F_XCLK, dev->board.xclk);
411 em28xx_initialize_mt9m111(dev);
412
Frank Schaefer92972852014-03-24 16:33:15 -0300413 v4l2->vinmode = 0x0a;
414 v4l2->vinctl = 0x00;
Frank Schaefer855ff382013-03-27 17:06:31 -0300415
416 break;
Frank Schaefere4b71312013-03-27 17:06:36 -0300417 case EM28XX_OV2640:
418 {
419 struct v4l2_subdev *subdev;
420 struct i2c_board_info ov2640_info = {
421 .type = "ov2640",
422 .flags = I2C_CLIENT_SCCB,
Guennadi Liakhovetskifc5d0f82013-08-28 10:28:28 -0300423 .addr = client->addr,
Frank Schaefere4b71312013-03-27 17:06:36 -0300424 .platform_data = &camlink,
425 };
Hans Verkuilebf984b2015-04-09 04:05:59 -0300426 struct v4l2_subdev_format format = {
427 .which = V4L2_SUBDEV_FORMAT_ACTIVE,
428 };
Frank Schaefere4b71312013-03-27 17:06:36 -0300429
430 /*
431 * FIXME: sensor supports resolutions up to 1600x1200, but
432 * resolution setting/switching needs to be modified to
433 * - switch sensor output resolution (including further
434 * configuration changes)
435 * - adjust bridge xclk
436 * - disable 16 bit (12 bit) output formats on high resolutions
437 */
Frank Schaeferd7dc18d2014-03-24 16:33:19 -0300438 v4l2->sensor_xres = 640;
439 v4l2->sensor_yres = 480;
Frank Schaefere4b71312013-03-27 17:06:36 -0300440
441 subdev =
Frank Schaefer50153892014-07-25 14:48:55 -0300442 v4l2_i2c_new_subdev_board(&v4l2->v4l2_dev, adap,
Frank Schaefere4b71312013-03-27 17:06:36 -0300443 &ov2640_info, NULL);
Guennadi Liakhovetskifc5d0f82013-08-28 10:28:28 -0300444 if (NULL == subdev) {
445 ret = -ENODEV;
446 break;
447 }
Frank Schaefere4b71312013-03-27 17:06:36 -0300448
Hans Verkuilebf984b2015-04-09 04:05:59 -0300449 format.format.code = MEDIA_BUS_FMT_YUYV8_2X8;
450 format.format.width = 640;
451 format.format.height = 480;
452 v4l2_subdev_call(subdev, pad, set_fmt, NULL, &format);
Frank Schaefere4b71312013-03-27 17:06:36 -0300453
454 /* NOTE: for UXGA=1600x1200 switch to 12MHz */
455 dev->board.xclk = EM28XX_XCLK_FREQUENCY_24MHZ;
456 em28xx_write_reg(dev, EM28XX_R0F_XCLK, dev->board.xclk);
Frank Schaefer92972852014-03-24 16:33:15 -0300457 v4l2->vinmode = 0x08;
458 v4l2->vinctl = 0x00;
Frank Schaefere4b71312013-03-27 17:06:36 -0300459
460 break;
461 }
Frank Schaefer855ff382013-03-27 17:06:31 -0300462 case EM28XX_NOSENSOR:
463 default:
Guennadi Liakhovetskifc5d0f82013-08-28 10:28:28 -0300464 ret = -EINVAL;
Frank Schaefer855ff382013-03-27 17:06:31 -0300465 }
466
Guennadi Liakhovetskifc5d0f82013-08-28 10:28:28 -0300467 if (ret < 0) {
Frank Schaefer2c52a2f2014-03-24 16:33:11 -0300468 v4l2_clk_unregister_fixed(v4l2->clk);
469 v4l2->clk = NULL;
Guennadi Liakhovetskifc5d0f82013-08-28 10:28:28 -0300470 }
471
472 return ret;
Frank Schaefer855ff382013-03-27 17:06:31 -0300473}
Mauro Carvalho Chehab01c28192013-12-22 13:27:02 -0300474EXPORT_SYMBOL_GPL(em28xx_init_camera);