blob: 8de1316a276d1fd6ca2a4474cacddf67fa543dbb [file] [log] [blame]
Mauro Carvalho Chehab7dfba002009-06-29 05:41:26 -03001/*
2 * mt9v011 -Micron 1/4-Inch VGA Digital Image Sensor
3 *
4 * Copyright (c) 2009 Mauro Carvalho Chehab (mchehab@redhat.com)
5 * This code is placed under the terms of the GNU General Public License v2
6 */
7
8#include <linux/i2c.h>
9#include <linux/videodev2.h>
10#include <linux/delay.h>
Mauro Carvalho Chehabe11206e2009-07-14 02:38:18 -030011#include <asm/div64.h>
Mauro Carvalho Chehab7dfba002009-06-29 05:41:26 -030012#include <media/v4l2-device.h>
13#include "mt9v011.h"
14#include <media/v4l2-i2c-drv.h>
15#include <media/v4l2-chip-ident.h>
16
17MODULE_DESCRIPTION("Micron mt9v011 sensor driver");
18MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
19MODULE_LICENSE("GPL");
20
21
22static int debug;
23module_param(debug, int, 0);
24MODULE_PARM_DESC(debug, "Debug level (0-2)");
25
26/* supported controls */
27static struct v4l2_queryctrl mt9v011_qctrl[] = {
28 {
29 .id = V4L2_CID_GAIN,
30 .type = V4L2_CTRL_TYPE_INTEGER,
31 .name = "Gain",
32 .minimum = 0,
33 .maximum = (1 << 10) - 1,
34 .step = 1,
35 .default_value = 0x0020,
36 .flags = 0,
37 }, {
38 .id = V4L2_CID_RED_BALANCE,
39 .type = V4L2_CTRL_TYPE_INTEGER,
40 .name = "Red Balance",
41 .minimum = -1 << 9,
42 .maximum = (1 << 9) - 1,
43 .step = 1,
44 .default_value = 0,
45 .flags = 0,
46 }, {
47 .id = V4L2_CID_BLUE_BALANCE,
48 .type = V4L2_CTRL_TYPE_INTEGER,
49 .name = "Blue Balance",
50 .minimum = -1 << 9,
51 .maximum = (1 << 9) - 1,
52 .step = 1,
53 .default_value = 0,
54 .flags = 0,
55 },
56};
57
58struct mt9v011 {
59 struct v4l2_subdev sd;
Mauro Carvalho Chehab27fe4a32009-07-04 08:03:48 -030060 unsigned width, height;
Mauro Carvalho Chehabe11206e2009-07-14 02:38:18 -030061 unsigned xtal;
Mauro Carvalho Chehab7dfba002009-06-29 05:41:26 -030062
63 u16 global_gain, red_bal, blue_bal;
64};
65
66static inline struct mt9v011 *to_mt9v011(struct v4l2_subdev *sd)
67{
68 return container_of(sd, struct mt9v011, sd);
69}
70
71static int mt9v011_read(struct v4l2_subdev *sd, unsigned char addr)
72{
73 struct i2c_client *c = v4l2_get_subdevdata(sd);
74 __be16 buffer;
75 int rc, val;
76
Mauro Carvalho Chehabfbe28002009-06-29 11:12:05 -030077 rc = i2c_master_send(c, &addr, 1);
78 if (rc != 1)
Mauro Carvalho Chehab7dfba002009-06-29 05:41:26 -030079 v4l2_dbg(0, debug, sd,
80 "i2c i/o error: rc == %d (should be 1)\n", rc);
81
82 msleep(10);
83
Mauro Carvalho Chehabfbe28002009-06-29 11:12:05 -030084 rc = i2c_master_recv(c, (char *)&buffer, 2);
85 if (rc != 2)
Mauro Carvalho Chehab7dfba002009-06-29 05:41:26 -030086 v4l2_dbg(0, debug, sd,
Mauro Carvalho Chehabfbe28002009-06-29 11:12:05 -030087 "i2c i/o error: rc == %d (should be 2)\n", rc);
Mauro Carvalho Chehab7dfba002009-06-29 05:41:26 -030088
89 val = be16_to_cpu(buffer);
90
91 v4l2_dbg(2, debug, sd, "mt9v011: read 0x%02x = 0x%04x\n", addr, val);
92
93 return val;
94}
95
96static void mt9v011_write(struct v4l2_subdev *sd, unsigned char addr,
97 u16 value)
98{
99 struct i2c_client *c = v4l2_get_subdevdata(sd);
100 unsigned char buffer[3];
101 int rc;
102
103 buffer[0] = addr;
104 buffer[1] = value >> 8;
105 buffer[2] = value & 0xff;
106
107 v4l2_dbg(2, debug, sd,
108 "mt9v011: writing 0x%02x 0x%04x\n", buffer[0], value);
Mauro Carvalho Chehab27fe4a32009-07-04 08:03:48 -0300109 rc = i2c_master_send(c, buffer, 3);
Mauro Carvalho Chehabfbe28002009-06-29 11:12:05 -0300110 if (rc != 3)
Mauro Carvalho Chehab7dfba002009-06-29 05:41:26 -0300111 v4l2_dbg(0, debug, sd,
112 "i2c i/o error: rc == %d (should be 3)\n", rc);
113}
114
115
116struct i2c_reg_value {
117 unsigned char reg;
118 u16 value;
119};
120
121/*
122 * Values used at the original driver
123 * Some values are marked as Reserved at the datasheet
124 */
125static const struct i2c_reg_value mt9v011_init_default[] = {
Mauro Carvalho Chehab7dfba002009-06-29 05:41:26 -0300126 { R0D_MT9V011_RESET, 0x0001 },
127 { R0D_MT9V011_RESET, 0x0000 },
Mauro Carvalho Chehabafe09f82009-06-29 11:03:22 -0300128
Mauro Carvalho Chehabafe09f82009-06-29 11:03:22 -0300129 { R0C_MT9V011_SHUTTER_DELAY, 0x0000 },
Mauro Carvalho Chehab6934e6f2009-07-04 08:15:11 -0300130 { R09_MT9V011_SHUTTER_WIDTH, 0x1fc },
Mauro Carvalho Chehabafe09f82009-06-29 11:03:22 -0300131
Mauro Carvalho Chehab6934e6f2009-07-04 08:15:11 -0300132 { R0A_MT9V011_CLK_SPEED, 0x0000 },
133 { R1E_MT9V011_DIGITAL_ZOOM, 0x0000 },
134 { R20_MT9V011_READ_MODE, 0x1000 },
Mauro Carvalho Chehabafe09f82009-06-29 11:03:22 -0300135
Mauro Carvalho Chehabe11206e2009-07-14 02:38:18 -0300136 { R07_MT9V011_OUT_CTRL, 0x0002 }, /* chip enable */
Mauro Carvalho Chehab7dfba002009-06-29 05:41:26 -0300137};
138
139static void set_balance(struct v4l2_subdev *sd)
140{
141 struct mt9v011 *core = to_mt9v011(sd);
142 u16 green1_gain, green2_gain, blue_gain, red_gain;
143
144 green1_gain = core->global_gain;
145 green2_gain = core->global_gain;
146
147 blue_gain = core->global_gain +
148 core->global_gain * core->blue_bal / (1 << 9);
149
150 red_gain = core->global_gain +
151 core->global_gain * core->blue_bal / (1 << 9);
152
153 mt9v011_write(sd, R2B_MT9V011_GREEN_1_GAIN, green1_gain);
154 mt9v011_write(sd, R2E_MT9V011_GREEN_2_GAIN, green1_gain);
155 mt9v011_write(sd, R2C_MT9V011_BLUE_GAIN, blue_gain);
156 mt9v011_write(sd, R2D_MT9V011_RED_GAIN, red_gain);
157}
158
Mauro Carvalho Chehab83053f72009-08-06 21:03:35 -0300159static void calc_fps(struct v4l2_subdev *sd, u32 *numerator, u32 *denominator)
Mauro Carvalho Chehabe11206e2009-07-14 02:38:18 -0300160{
161 struct mt9v011 *core = to_mt9v011(sd);
162 unsigned height, width, hblank, vblank, speed;
163 unsigned row_time, t_time;
164 u64 frames_per_ms;
165 unsigned tmp;
166
167 height = mt9v011_read(sd, R03_MT9V011_HEIGHT);
168 width = mt9v011_read(sd, R04_MT9V011_WIDTH);
169 hblank = mt9v011_read(sd, R05_MT9V011_HBLANK);
170 vblank = mt9v011_read(sd, R06_MT9V011_VBLANK);
171 speed = mt9v011_read(sd, R0A_MT9V011_CLK_SPEED);
172
173 row_time = (width + 113 + hblank) * (speed + 2);
174 t_time = row_time * (height + vblank + 1);
175
176 frames_per_ms = core->xtal * 1000l;
177 do_div(frames_per_ms, t_time);
178 tmp = frames_per_ms;
179
180 v4l2_dbg(1, debug, sd, "Programmed to %u.%03u fps (%d pixel clcks)\n",
181 tmp / 1000, tmp % 1000, t_time);
Mauro Carvalho Chehab83053f72009-08-06 21:03:35 -0300182
183 if (numerator && denominator) {
184 *numerator = 1000;
185 *denominator = (u32)frames_per_ms;
186 }
187}
188
189static u16 calc_speed(struct v4l2_subdev *sd, u32 numerator, u32 denominator)
190{
191 struct mt9v011 *core = to_mt9v011(sd);
192 unsigned height, width, hblank, vblank;
193 unsigned row_time, line_time;
194 u64 t_time, speed;
195
196 /* Avoid bogus calculus */
197 if (!numerator || !denominator)
198 return 0;
199
200 height = mt9v011_read(sd, R03_MT9V011_HEIGHT);
201 width = mt9v011_read(sd, R04_MT9V011_WIDTH);
202 hblank = mt9v011_read(sd, R05_MT9V011_HBLANK);
203 vblank = mt9v011_read(sd, R06_MT9V011_VBLANK);
204
205 row_time = width + 113 + hblank;
206 line_time = height + vblank + 1;
207
208 t_time = core->xtal * ((u64)numerator);
209 /* round to the closest value */
210 t_time += denominator / 2;
211 do_div(t_time, denominator);
212
213 speed = t_time;
214 do_div(speed, row_time * line_time);
215
216 /* Avoid having a negative value for speed */
217 if (speed < 2)
218 speed = 0;
219 else
220 speed -= 2;
221
222 /* Avoid speed overflow */
223 if (speed > 15)
224 return 15;
225
226 return (u16)speed;
Mauro Carvalho Chehabe11206e2009-07-14 02:38:18 -0300227}
228
Mauro Carvalho Chehab27fe4a32009-07-04 08:03:48 -0300229static void set_res(struct v4l2_subdev *sd)
230{
231 struct mt9v011 *core = to_mt9v011(sd);
232 unsigned vstart, hstart;
233
234 /*
235 * The mt9v011 doesn't have scaling. So, in order to select the desired
236 * resolution, we're cropping at the middle of the sensor.
237 * hblank and vblank should be adjusted, in order to warrant that
238 * we'll preserve the line timings for 30 fps, no matter what resolution
239 * is selected.
Mauro Carvalho Chehab6934e6f2009-07-04 08:15:11 -0300240 * NOTE: datasheet says that width (and height) should be filled with
241 * width-1. However, this doesn't work, since one pixel per line will
242 * be missing.
Mauro Carvalho Chehab27fe4a32009-07-04 08:03:48 -0300243 */
244
245 hstart = 14 + (640 - core->width) / 2;
246 mt9v011_write(sd, R02_MT9V011_COLSTART, hstart);
247 mt9v011_write(sd, R04_MT9V011_WIDTH, core->width);
248 mt9v011_write(sd, R05_MT9V011_HBLANK, 771 - core->width);
249
Mauro Carvalho Chehabc1806042009-07-14 02:39:19 -0300250 vstart = 8 + (480 - core->height) / 2;
Mauro Carvalho Chehab27fe4a32009-07-04 08:03:48 -0300251 mt9v011_write(sd, R01_MT9V011_ROWSTART, vstart);
252 mt9v011_write(sd, R03_MT9V011_HEIGHT, core->height);
253 mt9v011_write(sd, R06_MT9V011_VBLANK, 508 - core->height);
Mauro Carvalho Chehabe11206e2009-07-14 02:38:18 -0300254
Mauro Carvalho Chehab83053f72009-08-06 21:03:35 -0300255 calc_fps(sd, NULL, NULL);
Mauro Carvalho Chehab27fe4a32009-07-04 08:03:48 -0300256};
257
Mauro Carvalho Chehab7dfba002009-06-29 05:41:26 -0300258static int mt9v011_reset(struct v4l2_subdev *sd, u32 val)
259{
Mauro Carvalho Chehab7dfba002009-06-29 05:41:26 -0300260 int i;
261
Mauro Carvalho Chehab7dfba002009-06-29 05:41:26 -0300262 for (i = 0; i < ARRAY_SIZE(mt9v011_init_default); i++)
263 mt9v011_write(sd, mt9v011_init_default[i].reg,
264 mt9v011_init_default[i].value);
265
266 set_balance(sd);
Mauro Carvalho Chehab27fe4a32009-07-04 08:03:48 -0300267 set_res(sd);
Mauro Carvalho Chehab7dfba002009-06-29 05:41:26 -0300268
269 return 0;
270};
271
272static int mt9v011_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
273{
274 struct mt9v011 *core = to_mt9v011(sd);
275
276 v4l2_dbg(1, debug, sd, "g_ctrl called\n");
277
278 switch (ctrl->id) {
279 case V4L2_CID_GAIN:
280 ctrl->value = core->global_gain;
281 return 0;
282 case V4L2_CID_RED_BALANCE:
283 ctrl->value = core->red_bal;
284 return 0;
285 case V4L2_CID_BLUE_BALANCE:
286 ctrl->value = core->blue_bal;
287 return 0;
288 }
289 return -EINVAL;
290}
291
Mauro Carvalho Chehab98737402009-07-13 01:03:37 -0300292static int mt9v011_queryctrl(struct v4l2_subdev *sd, struct v4l2_queryctrl *qc)
293{
294 int i;
295
296 v4l2_dbg(1, debug, sd, "queryctrl called\n");
297
298 for (i = 0; i < ARRAY_SIZE(mt9v011_qctrl); i++)
299 if (qc->id && qc->id == mt9v011_qctrl[i].id) {
300 memcpy(qc, &(mt9v011_qctrl[i]),
301 sizeof(*qc));
302 return 0;
303 }
304
305 return -EINVAL;
306}
307
308
Mauro Carvalho Chehab7dfba002009-06-29 05:41:26 -0300309static int mt9v011_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
310{
311 struct mt9v011 *core = to_mt9v011(sd);
312 u8 i, n;
313 n = ARRAY_SIZE(mt9v011_qctrl);
314
315 for (i = 0; i < n; i++) {
316 if (ctrl->id != mt9v011_qctrl[i].id)
317 continue;
318 if (ctrl->value < mt9v011_qctrl[i].minimum ||
319 ctrl->value > mt9v011_qctrl[i].maximum)
320 return -ERANGE;
321 v4l2_dbg(1, debug, sd, "s_ctrl: id=%d, value=%d\n",
322 ctrl->id, ctrl->value);
323 break;
324 }
325
326 switch (ctrl->id) {
327 case V4L2_CID_GAIN:
328 core->global_gain = ctrl->value;
329 break;
330 case V4L2_CID_RED_BALANCE:
331 core->red_bal = ctrl->value;
332 break;
333 case V4L2_CID_BLUE_BALANCE:
334 core->blue_bal = ctrl->value;
335 break;
336 default:
337 return -EINVAL;
338 }
339
340 set_balance(sd);
341
342 return 0;
343}
344
Mauro Carvalho Chehab27fe4a32009-07-04 08:03:48 -0300345static int mt9v011_enum_fmt(struct v4l2_subdev *sd, struct v4l2_fmtdesc *fmt)
346{
347 if (fmt->index > 0)
348 return -EINVAL;
349
350 fmt->flags = 0;
351 strcpy(fmt->description, "8 bpp Bayer GRGR..BGBG");
352 fmt->pixelformat = V4L2_PIX_FMT_SGRBG8;
353
354 return 0;
355}
356
357static int mt9v011_try_fmt(struct v4l2_subdev *sd, struct v4l2_format *fmt)
358{
359 struct v4l2_pix_format *pix = &fmt->fmt.pix;
360
361 if (pix->pixelformat != V4L2_PIX_FMT_SGRBG8)
362 return -EINVAL;
363
364 v4l_bound_align_image(&pix->width, 48, 639, 1,
365 &pix->height, 32, 480, 1, 0);
366
367 return 0;
368}
369
Mauro Carvalho Chehab83053f72009-08-06 21:03:35 -0300370static int mt9v011_g_parm(struct v4l2_subdev *sd, struct v4l2_streamparm *parms)
371{
372 struct v4l2_captureparm *cp = &parms->parm.capture;
373
374 if (parms->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
375 return -EINVAL;
376
377 memset(cp, 0, sizeof(struct v4l2_captureparm));
378 cp->capability = V4L2_CAP_TIMEPERFRAME;
379 calc_fps(sd,
380 &cp->timeperframe.numerator,
381 &cp->timeperframe.denominator);
382
383 return 0;
384}
385
386static int mt9v011_s_parm(struct v4l2_subdev *sd, struct v4l2_streamparm *parms)
387{
388 struct v4l2_captureparm *cp = &parms->parm.capture;
389 struct v4l2_fract *tpf = &cp->timeperframe;
390 u16 speed;
391
392 if (parms->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
393 return -EINVAL;
394 if (cp->extendedmode != 0)
395 return -EINVAL;
396
397 speed = calc_speed(sd, tpf->numerator, tpf->denominator);
398
399 mt9v011_write(sd, R0A_MT9V011_CLK_SPEED, speed);
400 v4l2_dbg(1, debug, sd, "Setting speed to %d\n", speed);
401
402 /* Recalculate and update fps info */
403 calc_fps(sd, &tpf->numerator, &tpf->denominator);
404
405 return 0;
406}
407
Mauro Carvalho Chehab27fe4a32009-07-04 08:03:48 -0300408static int mt9v011_s_fmt(struct v4l2_subdev *sd, struct v4l2_format *fmt)
409{
410 struct v4l2_pix_format *pix = &fmt->fmt.pix;
411 struct mt9v011 *core = to_mt9v011(sd);
412 int rc;
413
414 rc = mt9v011_try_fmt(sd, fmt);
415 if (rc < 0)
416 return -EINVAL;
417
418 core->width = pix->width;
419 core->height = pix->height;
420
421 set_res(sd);
422
423 return 0;
424}
425
Mauro Carvalho Chehab2ea472f2009-07-14 03:14:21 -0300426static int mt9v011_s_config(struct v4l2_subdev *sd, int dumb, void *data)
427{
428 struct mt9v011 *core = to_mt9v011(sd);
429 unsigned *xtal = data;
430
431 v4l2_dbg(1, debug, sd, "s_config called\n");
432
433 if (xtal) {
434 core->xtal = *xtal;
435 v4l2_dbg(1, debug, sd, "xtal set to %d.%03d MHz\n",
436 *xtal / 1000000, (*xtal / 1000) % 1000);
437 }
438
439 return 0;
440}
441
Mauro Carvalho Chehab27fe4a32009-07-04 08:03:48 -0300442
Mauro Carvalho Chehab7dfba002009-06-29 05:41:26 -0300443#ifdef CONFIG_VIDEO_ADV_DEBUG
444static int mt9v011_g_register(struct v4l2_subdev *sd,
445 struct v4l2_dbg_register *reg)
446{
447 struct i2c_client *client = v4l2_get_subdevdata(sd);
448
449 if (!v4l2_chip_match_i2c_client(client, &reg->match))
450 return -EINVAL;
451 if (!capable(CAP_SYS_ADMIN))
452 return -EPERM;
453
454 reg->val = mt9v011_read(sd, reg->reg & 0xff);
455 reg->size = 2;
456
457 return 0;
458}
459
460static int mt9v011_s_register(struct v4l2_subdev *sd,
461 struct v4l2_dbg_register *reg)
462{
463 struct i2c_client *client = v4l2_get_subdevdata(sd);
464
465 if (!v4l2_chip_match_i2c_client(client, &reg->match))
466 return -EINVAL;
467 if (!capable(CAP_SYS_ADMIN))
468 return -EPERM;
469
470 mt9v011_write(sd, reg->reg & 0xff, reg->val & 0xffff);
471
472 return 0;
473}
474#endif
475
476static int mt9v011_g_chip_ident(struct v4l2_subdev *sd,
477 struct v4l2_dbg_chip_ident *chip)
478{
Mauro Carvalho Chehab296544e2009-07-27 08:24:29 -0300479 u16 version;
Mauro Carvalho Chehab7dfba002009-06-29 05:41:26 -0300480 struct i2c_client *client = v4l2_get_subdevdata(sd);
481
Mauro Carvalho Chehab296544e2009-07-27 08:24:29 -0300482 version = mt9v011_read(sd, R00_MT9V011_CHIP_VERSION);
483
Mauro Carvalho Chehab7dfba002009-06-29 05:41:26 -0300484 return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_MT9V011,
Mauro Carvalho Chehab296544e2009-07-27 08:24:29 -0300485 version);
Mauro Carvalho Chehab7dfba002009-06-29 05:41:26 -0300486}
487
488static const struct v4l2_subdev_core_ops mt9v011_core_ops = {
Mauro Carvalho Chehab98737402009-07-13 01:03:37 -0300489 .queryctrl = mt9v011_queryctrl,
Mauro Carvalho Chehab7dfba002009-06-29 05:41:26 -0300490 .g_ctrl = mt9v011_g_ctrl,
491 .s_ctrl = mt9v011_s_ctrl,
492 .reset = mt9v011_reset,
Mauro Carvalho Chehab2ea472f2009-07-14 03:14:21 -0300493 .s_config = mt9v011_s_config,
Mauro Carvalho Chehab7dfba002009-06-29 05:41:26 -0300494 .g_chip_ident = mt9v011_g_chip_ident,
495#ifdef CONFIG_VIDEO_ADV_DEBUG
496 .g_register = mt9v011_g_register,
497 .s_register = mt9v011_s_register,
498#endif
499};
500
Mauro Carvalho Chehab27fe4a32009-07-04 08:03:48 -0300501static const struct v4l2_subdev_video_ops mt9v011_video_ops = {
502 .enum_fmt = mt9v011_enum_fmt,
503 .try_fmt = mt9v011_try_fmt,
504 .s_fmt = mt9v011_s_fmt,
Mauro Carvalho Chehab83053f72009-08-06 21:03:35 -0300505 .g_parm = mt9v011_g_parm,
506 .s_parm = mt9v011_s_parm,
Mauro Carvalho Chehab27fe4a32009-07-04 08:03:48 -0300507};
508
Mauro Carvalho Chehab7dfba002009-06-29 05:41:26 -0300509static const struct v4l2_subdev_ops mt9v011_ops = {
Mauro Carvalho Chehab27fe4a32009-07-04 08:03:48 -0300510 .core = &mt9v011_core_ops,
511 .video = &mt9v011_video_ops,
Mauro Carvalho Chehab7dfba002009-06-29 05:41:26 -0300512};
513
514
515/****************************************************************************
516 I2C Client & Driver
517 ****************************************************************************/
518
519static int mt9v011_probe(struct i2c_client *c,
520 const struct i2c_device_id *id)
521{
Mauro Carvalho Chehab27fe4a32009-07-04 08:03:48 -0300522 u16 version;
Mauro Carvalho Chehab7dfba002009-06-29 05:41:26 -0300523 struct mt9v011 *core;
524 struct v4l2_subdev *sd;
525
526 /* Check if the adapter supports the needed features */
527 if (!i2c_check_functionality(c->adapter,
528 I2C_FUNC_SMBUS_READ_BYTE | I2C_FUNC_SMBUS_WRITE_BYTE_DATA))
529 return -EIO;
530
531 core = kzalloc(sizeof(struct mt9v011), GFP_KERNEL);
532 if (!core)
533 return -ENOMEM;
534
Mauro Carvalho Chehab7dfba002009-06-29 05:41:26 -0300535 sd = &core->sd;
536 v4l2_i2c_subdev_init(sd, c, &mt9v011_ops);
Mauro Carvalho Chehab27fe4a32009-07-04 08:03:48 -0300537
538 /* Check if the sensor is really a MT9V011 */
539 version = mt9v011_read(sd, R00_MT9V011_CHIP_VERSION);
Mauro Carvalho Chehab296544e2009-07-27 08:24:29 -0300540 if ((version != MT9V011_VERSION) &&
541 (version != MT9V011_REV_B_VERSION)) {
542 v4l2_info(sd, "*** unknown micron chip detected (0x%04x).\n",
Mauro Carvalho Chehab27fe4a32009-07-04 08:03:48 -0300543 version);
544 kfree(core);
545 return -EINVAL;
546 }
547
548 core->global_gain = 0x0024;
549 core->width = 640;
550 core->height = 480;
Mauro Carvalho Chehabe11206e2009-07-14 02:38:18 -0300551 core->xtal = 27000000; /* Hz */
Mauro Carvalho Chehab27fe4a32009-07-04 08:03:48 -0300552
Mauro Carvalho Chehab296544e2009-07-27 08:24:29 -0300553 v4l_info(c, "chip found @ 0x%02x (%s - chip version 0x%04x)\n",
554 c->addr << 1, c->adapter->name, version);
Mauro Carvalho Chehab7dfba002009-06-29 05:41:26 -0300555
556 return 0;
557}
558
559static int mt9v011_remove(struct i2c_client *c)
560{
561 struct v4l2_subdev *sd = i2c_get_clientdata(c);
562
563 v4l2_dbg(1, debug, sd,
564 "mt9v011.c: removing mt9v011 adapter on address 0x%x\n",
565 c->addr << 1);
566
567 v4l2_device_unregister_subdev(sd);
568 kfree(to_mt9v011(sd));
569 return 0;
570}
571
572/* ----------------------------------------------------------------------- */
573
574static const struct i2c_device_id mt9v011_id[] = {
575 { "mt9v011", 0 },
576 { }
577};
578MODULE_DEVICE_TABLE(i2c, mt9v011_id);
579
580static struct v4l2_i2c_driver_data v4l2_i2c_data = {
581 .name = "mt9v011",
582 .probe = mt9v011_probe,
583 .remove = mt9v011_remove,
584 .id_table = mt9v011_id,
585};