2 * OmniVision OV96xx Camera Driver
4 * Copyright (C) 2009 Marek Vasut <marek.vasut@gmail.com>
6 * Based on ov772x camera driver:
8 * Copyright (C) 2008 Renesas Solutions Corp.
9 * Kuninori Morimoto <morimoto.kuninori@renesas.com>
11 * Based on ov7670 and soc_camera_platform driver,
13 * Copyright 2006-7 Jonathan Corbet <corbet@lwn.net>
14 * Copyright (C) 2008 Magnus Damm
15 * Copyright (C) 2008, Guennadi Liakhovetski <kernel@pengutronix.de>
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License version 2 as
19 * published by the Free Software Foundation.
22 #include <linux/init.h>
23 #include <linux/module.h>
24 #include <linux/i2c.h>
25 #include <linux/slab.h>
26 #include <linux/delay.h>
27 #include <linux/videodev2.h>
28 #include <media/v4l2-chip-ident.h>
29 #include <media/v4l2-common.h>
30 #include <media/soc_camera.h>
34 /* default register setup */
35 static const struct ov9640_reg ov9640_regs_dflt
[] = {
36 { OV9640_COM5
, OV9640_COM5_SYSCLK
| OV9640_COM5_LONGEXP
},
37 { OV9640_COM6
, OV9640_COM6_OPT_BLC
| OV9640_COM6_ADBLC_BIAS
|
38 OV9640_COM6_FMT_RST
| OV9640_COM6_ADBLC_OPTEN
},
39 { OV9640_PSHFT
, OV9640_PSHFT_VAL(0x01) },
40 { OV9640_ACOM
, OV9640_ACOM_2X_ANALOG
| OV9640_ACOM_RSVD
},
41 { OV9640_TSLB
, OV9640_TSLB_YUYV_UYVY
},
42 { OV9640_COM16
, OV9640_COM16_RB_AVG
},
45 { 0x6c, 0x40 }, { 0x6d, 0x30 }, { 0x6e, 0x4b }, { 0x6f, 0x60 },
46 { 0x70, 0x70 }, { 0x71, 0x70 }, { 0x72, 0x70 }, { 0x73, 0x70 },
47 { 0x74, 0x60 }, { 0x75, 0x60 }, { 0x76, 0x50 }, { 0x77, 0x48 },
48 { 0x78, 0x3a }, { 0x79, 0x2e }, { 0x7a, 0x28 }, { 0x7b, 0x22 },
51 { 0x7c, 0x04 }, { 0x7d, 0x07 }, { 0x7e, 0x10 }, { 0x7f, 0x28 },
52 { 0x80, 0x36 }, { 0x81, 0x44 }, { 0x82, 0x52 }, { 0x83, 0x60 },
53 { 0x84, 0x6c }, { 0x85, 0x78 }, { 0x86, 0x8c }, { 0x87, 0x9e },
54 { 0x88, 0xbb }, { 0x89, 0xd2 }, { 0x8a, 0xe6 },
58 * NOTE: for YUV, alter the following registers:
59 * COM12 |= OV9640_COM12_YUV_AVG
61 * for RGB, alter the following registers:
62 * COM7 |= OV9640_COM7_RGB
63 * COM13 |= OV9640_COM13_RGB_AVG
64 * COM15 |= proper RGB color encoding mode
66 static const struct ov9640_reg ov9640_regs_qqcif
[] = {
67 { OV9640_CLKRC
, OV9640_CLKRC_DPLL_EN
| OV9640_CLKRC_DIV(0x0f) },
68 { OV9640_COM1
, OV9640_COM1_QQFMT
| OV9640_COM1_HREF_2SKIP
},
69 { OV9640_COM4
, OV9640_COM4_QQ_VP
| OV9640_COM4_RSVD
},
70 { OV9640_COM7
, OV9640_COM7_QCIF
},
71 { OV9640_COM12
, OV9640_COM12_RSVD
},
72 { OV9640_COM13
, OV9640_COM13_GAMMA_RAW
| OV9640_COM13_MATRIX_EN
},
73 { OV9640_COM15
, OV9640_COM15_OR_10F0
},
76 static const struct ov9640_reg ov9640_regs_qqvga
[] = {
77 { OV9640_CLKRC
, OV9640_CLKRC_DPLL_EN
| OV9640_CLKRC_DIV(0x07) },
78 { OV9640_COM1
, OV9640_COM1_QQFMT
| OV9640_COM1_HREF_2SKIP
},
79 { OV9640_COM4
, OV9640_COM4_QQ_VP
| OV9640_COM4_RSVD
},
80 { OV9640_COM7
, OV9640_COM7_QVGA
},
81 { OV9640_COM12
, OV9640_COM12_RSVD
},
82 { OV9640_COM13
, OV9640_COM13_GAMMA_RAW
| OV9640_COM13_MATRIX_EN
},
83 { OV9640_COM15
, OV9640_COM15_OR_10F0
},
86 static const struct ov9640_reg ov9640_regs_qcif
[] = {
87 { OV9640_CLKRC
, OV9640_CLKRC_DPLL_EN
| OV9640_CLKRC_DIV(0x07) },
88 { OV9640_COM4
, OV9640_COM4_QQ_VP
| OV9640_COM4_RSVD
},
89 { OV9640_COM7
, OV9640_COM7_QCIF
},
90 { OV9640_COM12
, OV9640_COM12_RSVD
},
91 { OV9640_COM13
, OV9640_COM13_GAMMA_RAW
| OV9640_COM13_MATRIX_EN
},
92 { OV9640_COM15
, OV9640_COM15_OR_10F0
},
95 static const struct ov9640_reg ov9640_regs_qvga
[] = {
96 { OV9640_CLKRC
, OV9640_CLKRC_DPLL_EN
| OV9640_CLKRC_DIV(0x03) },
97 { OV9640_COM4
, OV9640_COM4_QQ_VP
| OV9640_COM4_RSVD
},
98 { OV9640_COM7
, OV9640_COM7_QVGA
},
99 { OV9640_COM12
, OV9640_COM12_RSVD
},
100 { OV9640_COM13
, OV9640_COM13_GAMMA_RAW
| OV9640_COM13_MATRIX_EN
},
101 { OV9640_COM15
, OV9640_COM15_OR_10F0
},
104 static const struct ov9640_reg ov9640_regs_cif
[] = {
105 { OV9640_CLKRC
, OV9640_CLKRC_DPLL_EN
| OV9640_CLKRC_DIV(0x03) },
106 { OV9640_COM3
, OV9640_COM3_VP
},
107 { OV9640_COM7
, OV9640_COM7_CIF
},
108 { OV9640_COM12
, OV9640_COM12_RSVD
},
109 { OV9640_COM13
, OV9640_COM13_GAMMA_RAW
| OV9640_COM13_MATRIX_EN
},
110 { OV9640_COM15
, OV9640_COM15_OR_10F0
},
113 static const struct ov9640_reg ov9640_regs_vga
[] = {
114 { OV9640_CLKRC
, OV9640_CLKRC_DPLL_EN
| OV9640_CLKRC_DIV(0x01) },
115 { OV9640_COM3
, OV9640_COM3_VP
},
116 { OV9640_COM7
, OV9640_COM7_VGA
},
117 { OV9640_COM12
, OV9640_COM12_RSVD
},
118 { OV9640_COM13
, OV9640_COM13_GAMMA_RAW
| OV9640_COM13_MATRIX_EN
},
119 { OV9640_COM15
, OV9640_COM15_OR_10F0
},
122 static const struct ov9640_reg ov9640_regs_sxga
[] = {
123 { OV9640_CLKRC
, OV9640_CLKRC_DPLL_EN
| OV9640_CLKRC_DIV(0x01) },
124 { OV9640_COM3
, OV9640_COM3_VP
},
126 { OV9640_COM12
, OV9640_COM12_RSVD
},
127 { OV9640_COM13
, OV9640_COM13_GAMMA_RAW
| OV9640_COM13_MATRIX_EN
},
128 { OV9640_COM15
, OV9640_COM15_OR_10F0
},
131 static const struct ov9640_reg ov9640_regs_yuv
[] = {
132 { OV9640_MTX1
, 0x58 },
133 { OV9640_MTX2
, 0x48 },
134 { OV9640_MTX3
, 0x10 },
135 { OV9640_MTX4
, 0x28 },
136 { OV9640_MTX5
, 0x48 },
137 { OV9640_MTX6
, 0x70 },
138 { OV9640_MTX7
, 0x40 },
139 { OV9640_MTX8
, 0x40 },
140 { OV9640_MTX9
, 0x40 },
141 { OV9640_MTXS
, 0x0f },
144 static const struct ov9640_reg ov9640_regs_rgb
[] = {
145 { OV9640_MTX1
, 0x71 },
146 { OV9640_MTX2
, 0x3e },
147 { OV9640_MTX3
, 0x0c },
148 { OV9640_MTX4
, 0x33 },
149 { OV9640_MTX5
, 0x72 },
150 { OV9640_MTX6
, 0x00 },
151 { OV9640_MTX7
, 0x2b },
152 { OV9640_MTX8
, 0x66 },
153 { OV9640_MTX9
, 0xd2 },
154 { OV9640_MTXS
, 0x65 },
157 static enum v4l2_mbus_pixelcode ov9640_codes
[] = {
158 V4L2_MBUS_FMT_YUYV8_2X8_BE
,
159 V4L2_MBUS_FMT_RGB555_2X8_PADHI_LE
,
160 V4L2_MBUS_FMT_RGB565_2X8_LE
,
163 static const struct v4l2_queryctrl ov9640_controls
[] = {
165 .id
= V4L2_CID_VFLIP
,
166 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
167 .name
= "Flip Vertically",
174 .id
= V4L2_CID_HFLIP
,
175 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
176 .name
= "Flip Horizontally",
184 /* read a register */
185 static int ov9640_reg_read(struct i2c_client
*client
, u8 reg
, u8
*val
)
189 struct i2c_msg msg
= {
190 .addr
= client
->addr
,
196 ret
= i2c_transfer(client
->adapter
, &msg
, 1);
200 msg
.flags
= I2C_M_RD
;
201 ret
= i2c_transfer(client
->adapter
, &msg
, 1);
209 dev_err(&client
->dev
, "Failed reading register 0x%02x!\n", reg
);
213 /* write a register */
214 static int ov9640_reg_write(struct i2c_client
*client
, u8 reg
, u8 val
)
218 unsigned char data
[2] = { reg
, val
};
219 struct i2c_msg msg
= {
220 .addr
= client
->addr
,
226 ret
= i2c_transfer(client
->adapter
, &msg
, 1);
228 dev_err(&client
->dev
, "Failed writing register 0x%02x!\n", reg
);
232 /* we have to read the register back ... no idea why, maybe HW bug */
233 ret
= ov9640_reg_read(client
, reg
, &_val
);
235 dev_err(&client
->dev
,
236 "Failed reading back register 0x%02x!\n", reg
);
242 /* Read a register, alter its bits, write it back */
243 static int ov9640_reg_rmw(struct i2c_client
*client
, u8 reg
, u8 set
, u8 unset
)
248 ret
= ov9640_reg_read(client
, reg
, &val
);
250 dev_err(&client
->dev
,
251 "[Read]-Modify-Write of register %02x failed!\n", reg
);
258 ret
= ov9640_reg_write(client
, reg
, val
);
260 dev_err(&client
->dev
,
261 "Read-Modify-[Write] of register %02x failed!\n", reg
);
266 /* Soft reset the camera. This has nothing to do with the RESET pin! */
267 static int ov9640_reset(struct i2c_client
*client
)
271 ret
= ov9640_reg_write(client
, OV9640_COM7
, OV9640_COM7_SCCB_RESET
);
273 dev_err(&client
->dev
,
274 "An error occured while entering soft reset!\n");
279 /* Start/Stop streaming from the device */
280 static int ov9640_s_stream(struct v4l2_subdev
*sd
, int enable
)
285 /* Alter bus settings on camera side */
286 static int ov9640_set_bus_param(struct soc_camera_device
*icd
,
292 /* Request bus settings on camera side */
293 static unsigned long ov9640_query_bus_param(struct soc_camera_device
*icd
)
295 struct soc_camera_link
*icl
= to_soc_camera_link(icd
);
298 * REVISIT: the camera probably can do 10 bit transfers, but I don't
299 * have those pins connected on my hardware.
301 unsigned long flags
= SOCAM_PCLK_SAMPLE_RISING
| SOCAM_MASTER
|
302 SOCAM_VSYNC_ACTIVE_HIGH
| SOCAM_HSYNC_ACTIVE_HIGH
|
303 SOCAM_DATA_ACTIVE_HIGH
| SOCAM_DATAWIDTH_8
;
305 return soc_camera_apply_sensor_flags(icl
, flags
);
308 /* Get status of additional camera capabilities */
309 static int ov9640_g_ctrl(struct v4l2_subdev
*sd
, struct v4l2_control
*ctrl
)
311 struct i2c_client
*client
= sd
->priv
;
312 struct ov9640_priv
*priv
= container_of(i2c_get_clientdata(client
),
313 struct ov9640_priv
, subdev
);
317 ctrl
->value
= priv
->flag_vflip
;
320 ctrl
->value
= priv
->flag_hflip
;
326 /* Set status of additional camera capabilities */
327 static int ov9640_s_ctrl(struct v4l2_subdev
*sd
, struct v4l2_control
*ctrl
)
329 struct i2c_client
*client
= sd
->priv
;
330 struct ov9640_priv
*priv
= container_of(i2c_get_clientdata(client
),
331 struct ov9640_priv
, subdev
);
337 priv
->flag_vflip
= ctrl
->value
;
339 ret
= ov9640_reg_rmw(client
, OV9640_MVFP
,
342 ret
= ov9640_reg_rmw(client
, OV9640_MVFP
,
346 priv
->flag_hflip
= ctrl
->value
;
348 ret
= ov9640_reg_rmw(client
, OV9640_MVFP
,
351 ret
= ov9640_reg_rmw(client
, OV9640_MVFP
,
359 /* Get chip identification */
360 static int ov9640_g_chip_ident(struct v4l2_subdev
*sd
,
361 struct v4l2_dbg_chip_ident
*id
)
363 struct i2c_client
*client
= sd
->priv
;
364 struct ov9640_priv
*priv
= container_of(i2c_get_clientdata(client
),
365 struct ov9640_priv
, subdev
);
367 id
->ident
= priv
->model
;
368 id
->revision
= priv
->revision
;
373 #ifdef CONFIG_VIDEO_ADV_DEBUG
374 static int ov9640_get_register(struct v4l2_subdev
*sd
,
375 struct v4l2_dbg_register
*reg
)
377 struct i2c_client
*client
= sd
->priv
;
381 if (reg
->reg
& ~0xff)
386 ret
= ov9640_reg_read(client
, reg
->reg
, &val
);
390 reg
->val
= (__u64
)val
;
395 static int ov9640_set_register(struct v4l2_subdev
*sd
,
396 struct v4l2_dbg_register
*reg
)
398 struct i2c_client
*client
= sd
->priv
;
400 if (reg
->reg
& ~0xff || reg
->val
& ~0xff)
403 return ov9640_reg_write(client
, reg
->reg
, reg
->val
);
407 /* select nearest higher resolution for capture */
408 static void ov9640_res_roundup(u32
*width
, u32
*height
)
411 enum { QQCIF
, QQVGA
, QCIF
, QVGA
, CIF
, VGA
, SXGA
};
412 int res_x
[] = { 88, 160, 176, 320, 352, 640, 1280 };
413 int res_y
[] = { 72, 120, 144, 240, 288, 480, 960 };
415 for (i
= 0; i
< ARRAY_SIZE(res_x
); i
++) {
416 if (res_x
[i
] >= *width
&& res_y
[i
] >= *height
) {
423 *width
= res_x
[SXGA
];
424 *height
= res_y
[SXGA
];
427 /* Prepare necessary register changes depending on color encoding */
428 static void ov9640_alter_regs(enum v4l2_mbus_pixelcode code
,
429 struct ov9640_reg_alt
*alt
)
433 case V4L2_MBUS_FMT_YUYV8_2X8_BE
:
434 alt
->com12
= OV9640_COM12_YUV_AVG
;
435 alt
->com13
= OV9640_COM13_Y_DELAY_EN
|
436 OV9640_COM13_YUV_DLY(0x01);
438 case V4L2_MBUS_FMT_RGB555_2X8_PADHI_LE
:
439 alt
->com7
= OV9640_COM7_RGB
;
440 alt
->com13
= OV9640_COM13_RGB_AVG
;
441 alt
->com15
= OV9640_COM15_RGB_555
;
443 case V4L2_MBUS_FMT_RGB565_2X8_LE
:
444 alt
->com7
= OV9640_COM7_RGB
;
445 alt
->com13
= OV9640_COM13_RGB_AVG
;
446 alt
->com15
= OV9640_COM15_RGB_565
;
451 /* Setup registers according to resolution and color encoding */
452 static int ov9640_write_regs(struct i2c_client
*client
, u32 width
,
453 enum v4l2_mbus_pixelcode code
, struct ov9640_reg_alt
*alts
)
455 const struct ov9640_reg
*ov9640_regs
, *matrix_regs
;
456 int ov9640_regs_len
, matrix_regs_len
;
460 /* select register configuration for given resolution */
463 ov9640_regs
= ov9640_regs_qqcif
;
464 ov9640_regs_len
= ARRAY_SIZE(ov9640_regs_qqcif
);
467 ov9640_regs
= ov9640_regs_qqvga
;
468 ov9640_regs_len
= ARRAY_SIZE(ov9640_regs_qqvga
);
471 ov9640_regs
= ov9640_regs_qcif
;
472 ov9640_regs_len
= ARRAY_SIZE(ov9640_regs_qcif
);
475 ov9640_regs
= ov9640_regs_qvga
;
476 ov9640_regs_len
= ARRAY_SIZE(ov9640_regs_qvga
);
479 ov9640_regs
= ov9640_regs_cif
;
480 ov9640_regs_len
= ARRAY_SIZE(ov9640_regs_cif
);
483 ov9640_regs
= ov9640_regs_vga
;
484 ov9640_regs_len
= ARRAY_SIZE(ov9640_regs_vga
);
487 ov9640_regs
= ov9640_regs_sxga
;
488 ov9640_regs_len
= ARRAY_SIZE(ov9640_regs_sxga
);
491 dev_err(&client
->dev
, "Failed to select resolution!\n");
495 /* select color matrix configuration for given color encoding */
496 if (code
== V4L2_MBUS_FMT_YUYV8_2X8_BE
) {
497 matrix_regs
= ov9640_regs_yuv
;
498 matrix_regs_len
= ARRAY_SIZE(ov9640_regs_yuv
);
500 matrix_regs
= ov9640_regs_rgb
;
501 matrix_regs_len
= ARRAY_SIZE(ov9640_regs_rgb
);
504 /* write register settings into the module */
505 for (i
= 0; i
< ov9640_regs_len
; i
++) {
506 val
= ov9640_regs
[i
].val
;
508 switch (ov9640_regs
[i
].reg
) {
523 ret
= ov9640_reg_write(client
, ov9640_regs
[i
].reg
, val
);
528 /* write color matrix configuration into the module */
529 for (i
= 0; i
< matrix_regs_len
; i
++) {
530 ret
= ov9640_reg_write(client
, matrix_regs
[i
].reg
,
539 /* program default register values */
540 static int ov9640_prog_dflt(struct i2c_client
*client
)
544 for (i
= 0; i
< ARRAY_SIZE(ov9640_regs_dflt
); i
++) {
545 ret
= ov9640_reg_write(client
, ov9640_regs_dflt
[i
].reg
,
546 ov9640_regs_dflt
[i
].val
);
551 /* wait for the changes to actually happen, 140ms are not enough yet */
557 /* set the format we will capture in */
558 static int ov9640_s_fmt(struct v4l2_subdev
*sd
,
559 struct v4l2_mbus_framefmt
*mf
)
561 struct i2c_client
*client
= sd
->priv
;
562 struct ov9640_reg_alt alts
= {0};
563 enum v4l2_colorspace cspace
;
564 enum v4l2_mbus_pixelcode code
= mf
->code
;
567 ov9640_res_roundup(&mf
->width
, &mf
->height
);
568 ov9640_alter_regs(mf
->code
, &alts
);
570 ov9640_reset(client
);
572 ret
= ov9640_prog_dflt(client
);
577 case V4L2_MBUS_FMT_RGB555_2X8_PADHI_LE
:
578 case V4L2_MBUS_FMT_RGB565_2X8_LE
:
579 cspace
= V4L2_COLORSPACE_SRGB
;
582 code
= V4L2_MBUS_FMT_YUYV8_2X8_BE
;
583 case V4L2_MBUS_FMT_YUYV8_2X8_BE
:
584 cspace
= V4L2_COLORSPACE_JPEG
;
587 ret
= ov9640_write_regs(client
, mf
->width
, code
, &alts
);
590 mf
->colorspace
= cspace
;
596 static int ov9640_try_fmt(struct v4l2_subdev
*sd
,
597 struct v4l2_mbus_framefmt
*mf
)
599 ov9640_res_roundup(&mf
->width
, &mf
->height
);
601 mf
->field
= V4L2_FIELD_NONE
;
604 case V4L2_MBUS_FMT_RGB555_2X8_PADHI_LE
:
605 case V4L2_MBUS_FMT_RGB565_2X8_LE
:
606 mf
->colorspace
= V4L2_COLORSPACE_SRGB
;
609 mf
->code
= V4L2_MBUS_FMT_YUYV8_2X8_BE
;
610 case V4L2_MBUS_FMT_YUYV8_2X8_BE
:
611 mf
->colorspace
= V4L2_COLORSPACE_JPEG
;
617 static int ov9640_enum_fmt(struct v4l2_subdev
*sd
, int index
,
618 enum v4l2_mbus_pixelcode
*code
)
620 if ((unsigned int)index
>= ARRAY_SIZE(ov9640_codes
))
623 *code
= ov9640_codes
[index
];
627 static int ov9640_g_crop(struct v4l2_subdev
*sd
, struct v4l2_crop
*a
)
632 a
->c
.height
= H_SXGA
;
633 a
->type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
638 static int ov9640_cropcap(struct v4l2_subdev
*sd
, struct v4l2_cropcap
*a
)
642 a
->bounds
.width
= W_SXGA
;
643 a
->bounds
.height
= H_SXGA
;
644 a
->defrect
= a
->bounds
;
645 a
->type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
646 a
->pixelaspect
.numerator
= 1;
647 a
->pixelaspect
.denominator
= 1;
654 static int ov9640_video_probe(struct soc_camera_device
*icd
,
655 struct i2c_client
*client
)
657 struct ov9640_priv
*priv
= i2c_get_clientdata(client
);
658 u8 pid
, ver
, midh
, midl
;
663 * We must have a parent by now. And it cannot be a wrong one.
664 * So this entire test is completely redundant.
666 if (!icd
->dev
.parent
||
667 to_soc_camera_host(icd
->dev
.parent
)->nr
!= icd
->iface
) {
668 dev_err(&client
->dev
, "Parent missing or invalid!\n");
674 * check and show product ID and manufacturer ID
677 ret
= ov9640_reg_read(client
, OV9640_PID
, &pid
);
681 ret
= ov9640_reg_read(client
, OV9640_VER
, &ver
);
685 ret
= ov9640_reg_read(client
, OV9640_MIDH
, &midh
);
689 ret
= ov9640_reg_read(client
, OV9640_MIDL
, &midl
);
693 switch (VERSION(pid
, ver
)) {
696 priv
->model
= V4L2_IDENT_OV9640
;
700 priv
->model
= V4L2_IDENT_OV9640
;
704 dev_err(&client
->dev
, "Product ID error %x:%x\n", pid
, ver
);
709 dev_info(&client
->dev
, "%s Product ID %0x:%0x Manufacturer ID %x:%x\n",
710 devname
, pid
, ver
, midh
, midl
);
716 static struct soc_camera_ops ov9640_ops
= {
717 .set_bus_param
= ov9640_set_bus_param
,
718 .query_bus_param
= ov9640_query_bus_param
,
719 .controls
= ov9640_controls
,
720 .num_controls
= ARRAY_SIZE(ov9640_controls
),
723 static struct v4l2_subdev_core_ops ov9640_core_ops
= {
724 .g_ctrl
= ov9640_g_ctrl
,
725 .s_ctrl
= ov9640_s_ctrl
,
726 .g_chip_ident
= ov9640_g_chip_ident
,
727 #ifdef CONFIG_VIDEO_ADV_DEBUG
728 .g_register
= ov9640_get_register
,
729 .s_register
= ov9640_set_register
,
734 static struct v4l2_subdev_video_ops ov9640_video_ops
= {
735 .s_stream
= ov9640_s_stream
,
736 .s_mbus_fmt
= ov9640_s_fmt
,
737 .try_mbus_fmt
= ov9640_try_fmt
,
738 .enum_mbus_fmt
= ov9640_enum_fmt
,
739 .cropcap
= ov9640_cropcap
,
740 .g_crop
= ov9640_g_crop
,
744 static struct v4l2_subdev_ops ov9640_subdev_ops
= {
745 .core
= &ov9640_core_ops
,
746 .video
= &ov9640_video_ops
,
750 * i2c_driver function
752 static int ov9640_probe(struct i2c_client
*client
,
753 const struct i2c_device_id
*did
)
755 struct ov9640_priv
*priv
;
756 struct soc_camera_device
*icd
= client
->dev
.platform_data
;
757 struct soc_camera_link
*icl
;
761 dev_err(&client
->dev
, "Missing soc-camera data!\n");
765 icl
= to_soc_camera_link(icd
);
767 dev_err(&client
->dev
, "Missing platform_data for driver\n");
771 priv
= kzalloc(sizeof(struct ov9640_priv
), GFP_KERNEL
);
773 dev_err(&client
->dev
,
774 "Failed to allocate memory for private data!\n");
778 v4l2_i2c_subdev_init(&priv
->subdev
, client
, &ov9640_subdev_ops
);
780 icd
->ops
= &ov9640_ops
;
782 ret
= ov9640_video_probe(icd
, client
);
786 i2c_set_clientdata(client
, NULL
);
793 static int ov9640_remove(struct i2c_client
*client
)
795 struct ov9640_priv
*priv
= i2c_get_clientdata(client
);
797 i2c_set_clientdata(client
, NULL
);
802 static const struct i2c_device_id ov9640_id
[] = {
806 MODULE_DEVICE_TABLE(i2c
, ov9640_id
);
808 static struct i2c_driver ov9640_i2c_driver
= {
812 .probe
= ov9640_probe
,
813 .remove
= ov9640_remove
,
814 .id_table
= ov9640_id
,
817 static int __init
ov9640_module_init(void)
819 return i2c_add_driver(&ov9640_i2c_driver
);
822 static void __exit
ov9640_module_exit(void)
824 i2c_del_driver(&ov9640_i2c_driver
);
827 module_init(ov9640_module_init
);
828 module_exit(ov9640_module_exit
);
830 MODULE_DESCRIPTION("SoC Camera driver for OmniVision OV96xx");
831 MODULE_AUTHOR("Marek Vasut <marek.vasut@gmail.com>");
832 MODULE_LICENSE("GPL v2");