1 // SPDX-License-Identifier: GPL-2.0-only
3 * Omnivision OV2659 CMOS Image Sensor driver
5 * Copyright (C) 2015 Texas Instruments, Inc.
7 * Benoit Parrot <bparrot@ti.com>
8 * Lad, Prabhakar <prabhakar.csengg@gmail.com>
11 #include <linux/clk.h>
12 #include <linux/delay.h>
13 #include <linux/gpio/consumer.h>
14 #include <linux/i2c.h>
15 #include <linux/module.h>
16 #include <linux/of_graph.h>
17 #include <linux/pm_runtime.h>
19 #include <media/i2c/ov2659.h>
20 #include <media/v4l2-ctrls.h>
21 #include <media/v4l2-event.h>
22 #include <media/v4l2-fwnode.h>
23 #include <media/v4l2-image-sizes.h>
24 #include <media/v4l2-subdev.h>
26 #define DRIVER_NAME "ov2659"
29 * OV2659 register definitions
31 #define REG_SOFTWARE_STANDBY 0x0100
32 #define REG_SOFTWARE_RESET 0x0103
33 #define REG_IO_CTRL00 0x3000
34 #define REG_IO_CTRL01 0x3001
35 #define REG_IO_CTRL02 0x3002
36 #define REG_OUTPUT_VALUE00 0x3008
37 #define REG_OUTPUT_VALUE01 0x3009
38 #define REG_OUTPUT_VALUE02 0x300d
39 #define REG_OUTPUT_SELECT00 0x300e
40 #define REG_OUTPUT_SELECT01 0x300f
41 #define REG_OUTPUT_SELECT02 0x3010
42 #define REG_OUTPUT_DRIVE 0x3011
43 #define REG_INPUT_READOUT00 0x302d
44 #define REG_INPUT_READOUT01 0x302e
45 #define REG_INPUT_READOUT02 0x302f
47 #define REG_SC_PLL_CTRL0 0x3003
48 #define REG_SC_PLL_CTRL1 0x3004
49 #define REG_SC_PLL_CTRL2 0x3005
50 #define REG_SC_PLL_CTRL3 0x3006
51 #define REG_SC_CHIP_ID_H 0x300a
52 #define REG_SC_CHIP_ID_L 0x300b
53 #define REG_SC_PWC 0x3014
54 #define REG_SC_CLKRST0 0x301a
55 #define REG_SC_CLKRST1 0x301b
56 #define REG_SC_CLKRST2 0x301c
57 #define REG_SC_CLKRST3 0x301d
58 #define REG_SC_SUB_ID 0x302a
59 #define REG_SC_SCCB_ID 0x302b
61 #define REG_GROUP_ADDRESS_00 0x3200
62 #define REG_GROUP_ADDRESS_01 0x3201
63 #define REG_GROUP_ADDRESS_02 0x3202
64 #define REG_GROUP_ADDRESS_03 0x3203
65 #define REG_GROUP_ACCESS 0x3208
67 #define REG_AWB_R_GAIN_H 0x3400
68 #define REG_AWB_R_GAIN_L 0x3401
69 #define REG_AWB_G_GAIN_H 0x3402
70 #define REG_AWB_G_GAIN_L 0x3403
71 #define REG_AWB_B_GAIN_H 0x3404
72 #define REG_AWB_B_GAIN_L 0x3405
73 #define REG_AWB_MANUAL_CONTROL 0x3406
75 #define REG_TIMING_HS_H 0x3800
76 #define REG_TIMING_HS_L 0x3801
77 #define REG_TIMING_VS_H 0x3802
78 #define REG_TIMING_VS_L 0x3803
79 #define REG_TIMING_HW_H 0x3804
80 #define REG_TIMING_HW_L 0x3805
81 #define REG_TIMING_VH_H 0x3806
82 #define REG_TIMING_VH_L 0x3807
83 #define REG_TIMING_DVPHO_H 0x3808
84 #define REG_TIMING_DVPHO_L 0x3809
85 #define REG_TIMING_DVPVO_H 0x380a
86 #define REG_TIMING_DVPVO_L 0x380b
87 #define REG_TIMING_HTS_H 0x380c
88 #define REG_TIMING_HTS_L 0x380d
89 #define REG_TIMING_VTS_H 0x380e
90 #define REG_TIMING_VTS_L 0x380f
91 #define REG_TIMING_HOFFS_H 0x3810
92 #define REG_TIMING_HOFFS_L 0x3811
93 #define REG_TIMING_VOFFS_H 0x3812
94 #define REG_TIMING_VOFFS_L 0x3813
95 #define REG_TIMING_XINC 0x3814
96 #define REG_TIMING_YINC 0x3815
97 #define REG_TIMING_VERT_FORMAT 0x3820
98 #define REG_TIMING_HORIZ_FORMAT 0x3821
100 #define REG_FORMAT_CTRL00 0x4300
102 #define REG_VFIFO_READ_START_H 0x4608
103 #define REG_VFIFO_READ_START_L 0x4609
105 #define REG_DVP_CTRL02 0x4708
107 #define REG_ISP_CTRL00 0x5000
108 #define REG_ISP_CTRL01 0x5001
109 #define REG_ISP_CTRL02 0x5002
111 #define REG_LENC_RED_X0_H 0x500c
112 #define REG_LENC_RED_X0_L 0x500d
113 #define REG_LENC_RED_Y0_H 0x500e
114 #define REG_LENC_RED_Y0_L 0x500f
115 #define REG_LENC_RED_A1 0x5010
116 #define REG_LENC_RED_B1 0x5011
117 #define REG_LENC_RED_A2_B2 0x5012
118 #define REG_LENC_GREEN_X0_H 0x5013
119 #define REG_LENC_GREEN_X0_L 0x5014
120 #define REG_LENC_GREEN_Y0_H 0x5015
121 #define REG_LENC_GREEN_Y0_L 0x5016
122 #define REG_LENC_GREEN_A1 0x5017
123 #define REG_LENC_GREEN_B1 0x5018
124 #define REG_LENC_GREEN_A2_B2 0x5019
125 #define REG_LENC_BLUE_X0_H 0x501a
126 #define REG_LENC_BLUE_X0_L 0x501b
127 #define REG_LENC_BLUE_Y0_H 0x501c
128 #define REG_LENC_BLUE_Y0_L 0x501d
129 #define REG_LENC_BLUE_A1 0x501e
130 #define REG_LENC_BLUE_B1 0x501f
131 #define REG_LENC_BLUE_A2_B2 0x5020
133 #define REG_AWB_CTRL00 0x5035
134 #define REG_AWB_CTRL01 0x5036
135 #define REG_AWB_CTRL02 0x5037
136 #define REG_AWB_CTRL03 0x5038
137 #define REG_AWB_CTRL04 0x5039
138 #define REG_AWB_LOCAL_LIMIT 0x503a
139 #define REG_AWB_CTRL12 0x5049
140 #define REG_AWB_CTRL13 0x504a
141 #define REG_AWB_CTRL14 0x504b
143 #define REG_SHARPENMT_THRESH1 0x5064
144 #define REG_SHARPENMT_THRESH2 0x5065
145 #define REG_SHARPENMT_OFFSET1 0x5066
146 #define REG_SHARPENMT_OFFSET2 0x5067
147 #define REG_DENOISE_THRESH1 0x5068
148 #define REG_DENOISE_THRESH2 0x5069
149 #define REG_DENOISE_OFFSET1 0x506a
150 #define REG_DENOISE_OFFSET2 0x506b
151 #define REG_SHARPEN_THRESH1 0x506c
152 #define REG_SHARPEN_THRESH2 0x506d
153 #define REG_CIP_CTRL00 0x506e
154 #define REG_CIP_CTRL01 0x506f
156 #define REG_CMX_SIGN 0x5079
157 #define REG_CMX_MISC_CTRL 0x507a
159 #define REG_PRE_ISP_CTRL00 0x50a0
160 #define TEST_PATTERN_ENABLE BIT(7)
161 #define VERTICAL_COLOR_BAR_MASK 0x53
163 #define REG_NULL 0x0000 /* Array end token */
165 #define OV265X_ID(_msb, _lsb) ((_msb) << 8 | (_lsb))
166 #define OV2659_ID 0x2656
168 struct sensor_register
{
173 struct ov2659_framesize
{
177 const struct sensor_register
*regs
;
180 struct ov2659_pll_ctrl
{
186 struct ov2659_pixfmt
{
188 /* Output format Register Value (REG_FORMAT_CTRL00) */
189 struct sensor_register
*format_ctrl_regs
;
192 struct pll_ctrl_reg
{
198 struct v4l2_subdev sd
;
199 struct media_pad pad
;
200 struct v4l2_mbus_framefmt format
;
201 unsigned int xvclk_frequency
;
202 const struct ov2659_platform_data
*pdata
;
204 struct i2c_client
*client
;
205 struct v4l2_ctrl_handler ctrls
;
206 struct v4l2_ctrl
*link_frequency
;
208 const struct ov2659_framesize
*frame_size
;
209 struct sensor_register
*format_ctrl_regs
;
210 struct ov2659_pll_ctrl pll
;
212 /* used to control the sensor PWDN pin */
213 struct gpio_desc
*pwdn_gpio
;
214 /* used to control the sensor RESETB pin */
215 struct gpio_desc
*resetb_gpio
;
218 static const struct sensor_register ov2659_init_regs
[] = {
219 { REG_IO_CTRL00
, 0x03 },
220 { REG_IO_CTRL01
, 0xff },
221 { REG_IO_CTRL02
, 0xe0 },
229 { REG_TIMING_HS_H
, 0x00 },
230 { REG_TIMING_HS_L
, 0x00 },
231 { REG_TIMING_VS_H
, 0x00 },
232 { REG_TIMING_VS_L
, 0x00 },
233 { REG_TIMING_HW_H
, 0x06 },
234 { REG_TIMING_HW_L
, 0x5f },
235 { REG_TIMING_VH_H
, 0x04 },
236 { REG_TIMING_VH_L
, 0xb7 },
237 { REG_TIMING_DVPHO_H
, 0x03 },
238 { REG_TIMING_DVPHO_L
, 0x20 },
239 { REG_TIMING_DVPVO_H
, 0x02 },
240 { REG_TIMING_DVPVO_L
, 0x58 },
241 { REG_TIMING_HTS_H
, 0x05 },
242 { REG_TIMING_HTS_L
, 0x14 },
243 { REG_TIMING_VTS_H
, 0x02 },
244 { REG_TIMING_VTS_L
, 0x68 },
245 { REG_TIMING_HOFFS_L
, 0x08 },
246 { REG_TIMING_VOFFS_L
, 0x02 },
247 { REG_TIMING_XINC
, 0x31 },
248 { REG_TIMING_YINC
, 0x31 },
259 { REG_DVP_CTRL02
, 0x01 },
267 { REG_TIMING_VERT_FORMAT
, 0x81 },
268 { REG_TIMING_HORIZ_FORMAT
, 0x01 },
270 { REG_VFIFO_READ_START_H
, 0x00 },
271 { REG_VFIFO_READ_START_L
, 0x80 },
272 { REG_FORMAT_CTRL00
, 0x30 },
274 { REG_ISP_CTRL00
, 0xfb },
275 { REG_ISP_CTRL01
, 0x1f },
276 { REG_ISP_CTRL02
, 0x00 },
302 { REG_CMX_SIGN
, 0x98 },
303 { REG_CMX_MISC_CTRL
, 0x21 },
304 { REG_AWB_CTRL00
, 0x6a },
305 { REG_AWB_CTRL01
, 0x11 },
306 { REG_AWB_CTRL02
, 0x92 },
307 { REG_AWB_CTRL03
, 0x21 },
308 { REG_AWB_CTRL04
, 0xe1 },
309 { REG_AWB_LOCAL_LIMIT
, 0x01 },
323 { REG_AWB_CTRL12
, 0x70 },
324 { REG_AWB_CTRL13
, 0xf0 },
325 { REG_AWB_CTRL14
, 0xf0 },
326 { REG_LENC_RED_X0_H
, 0x03 },
327 { REG_LENC_RED_X0_L
, 0x20 },
328 { REG_LENC_RED_Y0_H
, 0x02 },
329 { REG_LENC_RED_Y0_L
, 0x5c },
330 { REG_LENC_RED_A1
, 0x48 },
331 { REG_LENC_RED_B1
, 0x00 },
332 { REG_LENC_RED_A2_B2
, 0x66 },
333 { REG_LENC_GREEN_X0_H
, 0x03 },
334 { REG_LENC_GREEN_X0_L
, 0x30 },
335 { REG_LENC_GREEN_Y0_H
, 0x02 },
336 { REG_LENC_GREEN_Y0_L
, 0x7c },
337 { REG_LENC_GREEN_A1
, 0x40 },
338 { REG_LENC_GREEN_B1
, 0x00 },
339 { REG_LENC_GREEN_A2_B2
, 0x66 },
340 { REG_LENC_BLUE_X0_H
, 0x03 },
341 { REG_LENC_BLUE_X0_L
, 0x10 },
342 { REG_LENC_BLUE_Y0_H
, 0x02 },
343 { REG_LENC_BLUE_Y0_L
, 0x7c },
344 { REG_LENC_BLUE_A1
, 0x3a },
345 { REG_LENC_BLUE_B1
, 0x00 },
346 { REG_LENC_BLUE_A2_B2
, 0x66 },
347 { REG_CIP_CTRL00
, 0x44 },
348 { REG_SHARPENMT_THRESH1
, 0x08 },
349 { REG_SHARPENMT_THRESH2
, 0x10 },
350 { REG_SHARPENMT_OFFSET1
, 0x12 },
351 { REG_SHARPENMT_OFFSET2
, 0x02 },
352 { REG_SHARPEN_THRESH1
, 0x08 },
353 { REG_SHARPEN_THRESH2
, 0x10 },
354 { REG_CIP_CTRL01
, 0xa6 },
355 { REG_DENOISE_THRESH1
, 0x08 },
356 { REG_DENOISE_THRESH2
, 0x10 },
357 { REG_DENOISE_OFFSET1
, 0x04 },
358 { REG_DENOISE_OFFSET2
, 0x12 },
362 { REG_CMX_MISC_CTRL
, 0x01 },
380 static struct sensor_register ov2659_720p
[] = {
381 { REG_TIMING_HS_H
, 0x00 },
382 { REG_TIMING_HS_L
, 0xa0 },
383 { REG_TIMING_VS_H
, 0x00 },
384 { REG_TIMING_VS_L
, 0xf0 },
385 { REG_TIMING_HW_H
, 0x05 },
386 { REG_TIMING_HW_L
, 0xbf },
387 { REG_TIMING_VH_H
, 0x03 },
388 { REG_TIMING_VH_L
, 0xcb },
389 { REG_TIMING_DVPHO_H
, 0x05 },
390 { REG_TIMING_DVPHO_L
, 0x00 },
391 { REG_TIMING_DVPVO_H
, 0x02 },
392 { REG_TIMING_DVPVO_L
, 0xd0 },
393 { REG_TIMING_HTS_H
, 0x06 },
394 { REG_TIMING_HTS_L
, 0x4c },
395 { REG_TIMING_VTS_H
, 0x02 },
396 { REG_TIMING_VTS_L
, 0xe8 },
397 { REG_TIMING_HOFFS_L
, 0x10 },
398 { REG_TIMING_VOFFS_L
, 0x06 },
399 { REG_TIMING_XINC
, 0x11 },
400 { REG_TIMING_YINC
, 0x11 },
401 { REG_TIMING_VERT_FORMAT
, 0x80 },
402 { REG_TIMING_HORIZ_FORMAT
, 0x00 },
408 { REG_VFIFO_READ_START_H
, 0x00 },
409 { REG_VFIFO_READ_START_L
, 0x80 },
410 { REG_ISP_CTRL02
, 0x00 },
415 static struct sensor_register ov2659_uxga
[] = {
416 { REG_TIMING_HS_H
, 0x00 },
417 { REG_TIMING_HS_L
, 0x00 },
418 { REG_TIMING_VS_H
, 0x00 },
419 { REG_TIMING_VS_L
, 0x00 },
420 { REG_TIMING_HW_H
, 0x06 },
421 { REG_TIMING_HW_L
, 0x5f },
422 { REG_TIMING_VH_H
, 0x04 },
423 { REG_TIMING_VH_L
, 0xbb },
424 { REG_TIMING_DVPHO_H
, 0x06 },
425 { REG_TIMING_DVPHO_L
, 0x40 },
426 { REG_TIMING_DVPVO_H
, 0x04 },
427 { REG_TIMING_DVPVO_L
, 0xb0 },
428 { REG_TIMING_HTS_H
, 0x07 },
429 { REG_TIMING_HTS_L
, 0x9f },
430 { REG_TIMING_VTS_H
, 0x04 },
431 { REG_TIMING_VTS_L
, 0xd0 },
432 { REG_TIMING_HOFFS_L
, 0x10 },
433 { REG_TIMING_VOFFS_L
, 0x06 },
434 { REG_TIMING_XINC
, 0x11 },
435 { REG_TIMING_YINC
, 0x11 },
453 { REG_TIMING_VERT_FORMAT
, 0x80 },
454 { REG_TIMING_HORIZ_FORMAT
, 0x00 },
456 { REG_VFIFO_READ_START_H
, 0x00 },
457 { REG_VFIFO_READ_START_L
, 0x80 },
458 { REG_ISP_CTRL02
, 0x00 },
463 static struct sensor_register ov2659_sxga
[] = {
464 { REG_TIMING_HS_H
, 0x00 },
465 { REG_TIMING_HS_L
, 0x00 },
466 { REG_TIMING_VS_H
, 0x00 },
467 { REG_TIMING_VS_L
, 0x00 },
468 { REG_TIMING_HW_H
, 0x06 },
469 { REG_TIMING_HW_L
, 0x5f },
470 { REG_TIMING_VH_H
, 0x04 },
471 { REG_TIMING_VH_L
, 0xb7 },
472 { REG_TIMING_DVPHO_H
, 0x05 },
473 { REG_TIMING_DVPHO_L
, 0x00 },
474 { REG_TIMING_DVPVO_H
, 0x04 },
475 { REG_TIMING_DVPVO_L
, 0x00 },
476 { REG_TIMING_HTS_H
, 0x07 },
477 { REG_TIMING_HTS_L
, 0x9c },
478 { REG_TIMING_VTS_H
, 0x04 },
479 { REG_TIMING_VTS_L
, 0xd0 },
480 { REG_TIMING_HOFFS_L
, 0x10 },
481 { REG_TIMING_VOFFS_L
, 0x06 },
482 { REG_TIMING_XINC
, 0x11 },
483 { REG_TIMING_YINC
, 0x11 },
501 { REG_TIMING_VERT_FORMAT
, 0x80 },
502 { REG_TIMING_HORIZ_FORMAT
, 0x00 },
504 { REG_VFIFO_READ_START_H
, 0x00 },
505 { REG_VFIFO_READ_START_L
, 0x80 },
506 { REG_ISP_CTRL02
, 0x00 },
511 static struct sensor_register ov2659_xga
[] = {
512 { REG_TIMING_HS_H
, 0x00 },
513 { REG_TIMING_HS_L
, 0x00 },
514 { REG_TIMING_VS_H
, 0x00 },
515 { REG_TIMING_VS_L
, 0x00 },
516 { REG_TIMING_HW_H
, 0x06 },
517 { REG_TIMING_HW_L
, 0x5f },
518 { REG_TIMING_VH_H
, 0x04 },
519 { REG_TIMING_VH_L
, 0xb7 },
520 { REG_TIMING_DVPHO_H
, 0x04 },
521 { REG_TIMING_DVPHO_L
, 0x00 },
522 { REG_TIMING_DVPVO_H
, 0x03 },
523 { REG_TIMING_DVPVO_L
, 0x00 },
524 { REG_TIMING_HTS_H
, 0x07 },
525 { REG_TIMING_HTS_L
, 0x9c },
526 { REG_TIMING_VTS_H
, 0x04 },
527 { REG_TIMING_VTS_L
, 0xd0 },
528 { REG_TIMING_HOFFS_L
, 0x10 },
529 { REG_TIMING_VOFFS_L
, 0x06 },
530 { REG_TIMING_XINC
, 0x11 },
531 { REG_TIMING_YINC
, 0x11 },
549 { REG_TIMING_VERT_FORMAT
, 0x80 },
550 { REG_TIMING_HORIZ_FORMAT
, 0x00 },
552 { REG_VFIFO_READ_START_H
, 0x00 },
553 { REG_VFIFO_READ_START_L
, 0x80 },
554 { REG_ISP_CTRL02
, 0x00 },
559 static struct sensor_register ov2659_svga
[] = {
560 { REG_TIMING_HS_H
, 0x00 },
561 { REG_TIMING_HS_L
, 0x00 },
562 { REG_TIMING_VS_H
, 0x00 },
563 { REG_TIMING_VS_L
, 0x00 },
564 { REG_TIMING_HW_H
, 0x06 },
565 { REG_TIMING_HW_L
, 0x5f },
566 { REG_TIMING_VH_H
, 0x04 },
567 { REG_TIMING_VH_L
, 0xb7 },
568 { REG_TIMING_DVPHO_H
, 0x03 },
569 { REG_TIMING_DVPHO_L
, 0x20 },
570 { REG_TIMING_DVPVO_H
, 0x02 },
571 { REG_TIMING_DVPVO_L
, 0x58 },
572 { REG_TIMING_HTS_H
, 0x05 },
573 { REG_TIMING_HTS_L
, 0x14 },
574 { REG_TIMING_VTS_H
, 0x02 },
575 { REG_TIMING_VTS_L
, 0x68 },
576 { REG_TIMING_HOFFS_L
, 0x08 },
577 { REG_TIMING_VOFFS_L
, 0x02 },
578 { REG_TIMING_XINC
, 0x31 },
579 { REG_TIMING_YINC
, 0x31 },
597 { REG_TIMING_VERT_FORMAT
, 0x81 },
598 { REG_TIMING_HORIZ_FORMAT
, 0x01 },
600 { REG_VFIFO_READ_START_H
, 0x00 },
601 { REG_VFIFO_READ_START_L
, 0x80 },
602 { REG_ISP_CTRL02
, 0x00 },
607 static struct sensor_register ov2659_vga
[] = {
608 { REG_TIMING_HS_H
, 0x00 },
609 { REG_TIMING_HS_L
, 0x00 },
610 { REG_TIMING_VS_H
, 0x00 },
611 { REG_TIMING_VS_L
, 0x00 },
612 { REG_TIMING_HW_H
, 0x06 },
613 { REG_TIMING_HW_L
, 0x5f },
614 { REG_TIMING_VH_H
, 0x04 },
615 { REG_TIMING_VH_L
, 0xb7 },
616 { REG_TIMING_DVPHO_H
, 0x02 },
617 { REG_TIMING_DVPHO_L
, 0x80 },
618 { REG_TIMING_DVPVO_H
, 0x01 },
619 { REG_TIMING_DVPVO_L
, 0xe0 },
620 { REG_TIMING_HTS_H
, 0x05 },
621 { REG_TIMING_HTS_L
, 0x14 },
622 { REG_TIMING_VTS_H
, 0x02 },
623 { REG_TIMING_VTS_L
, 0x68 },
624 { REG_TIMING_HOFFS_L
, 0x08 },
625 { REG_TIMING_VOFFS_L
, 0x02 },
626 { REG_TIMING_XINC
, 0x31 },
627 { REG_TIMING_YINC
, 0x31 },
645 { REG_TIMING_VERT_FORMAT
, 0x81 },
646 { REG_TIMING_HORIZ_FORMAT
, 0x01 },
648 { REG_VFIFO_READ_START_H
, 0x00 },
649 { REG_VFIFO_READ_START_L
, 0xa0 },
650 { REG_ISP_CTRL02
, 0x10 },
655 static struct sensor_register ov2659_qvga
[] = {
656 { REG_TIMING_HS_H
, 0x00 },
657 { REG_TIMING_HS_L
, 0x00 },
658 { REG_TIMING_VS_H
, 0x00 },
659 { REG_TIMING_VS_L
, 0x00 },
660 { REG_TIMING_HW_H
, 0x06 },
661 { REG_TIMING_HW_L
, 0x5f },
662 { REG_TIMING_VH_H
, 0x04 },
663 { REG_TIMING_VH_L
, 0xb7 },
664 { REG_TIMING_DVPHO_H
, 0x01 },
665 { REG_TIMING_DVPHO_L
, 0x40 },
666 { REG_TIMING_DVPVO_H
, 0x00 },
667 { REG_TIMING_DVPVO_L
, 0xf0 },
668 { REG_TIMING_HTS_H
, 0x05 },
669 { REG_TIMING_HTS_L
, 0x14 },
670 { REG_TIMING_VTS_H
, 0x02 },
671 { REG_TIMING_VTS_L
, 0x68 },
672 { REG_TIMING_HOFFS_L
, 0x08 },
673 { REG_TIMING_VOFFS_L
, 0x02 },
674 { REG_TIMING_XINC
, 0x31 },
675 { REG_TIMING_YINC
, 0x31 },
693 { REG_TIMING_VERT_FORMAT
, 0x81 },
694 { REG_TIMING_HORIZ_FORMAT
, 0x01 },
696 { REG_VFIFO_READ_START_H
, 0x00 },
697 { REG_VFIFO_READ_START_L
, 0xa0 },
698 { REG_ISP_CTRL02
, 0x10 },
702 static const struct pll_ctrl_reg ctrl3
[] = {
719 static const struct pll_ctrl_reg ctrl1
[] = {
738 static const struct ov2659_framesize ov2659_framesizes
[] = {
743 .max_exp_lines
= 248,
748 .max_exp_lines
= 498,
753 .max_exp_lines
= 498,
758 .max_exp_lines
= 498,
763 .max_exp_lines
= 498,
768 .max_exp_lines
= 1048,
773 .max_exp_lines
= 498,
778 static struct sensor_register ov2659_format_yuyv
[] = {
779 { REG_FORMAT_CTRL00
, 0x30 },
784 static struct sensor_register ov2659_format_uyvy
[] = {
785 { REG_FORMAT_CTRL00
, 0x32 },
790 static struct sensor_register ov2659_format_bggr
[] = {
791 { REG_FORMAT_CTRL00
, 0x00 },
796 static struct sensor_register ov2659_format_rgb565
[] = {
797 { REG_FORMAT_CTRL00
, 0x60 },
801 static const struct ov2659_pixfmt ov2659_formats
[] = {
803 .code
= MEDIA_BUS_FMT_YUYV8_2X8
,
804 .format_ctrl_regs
= ov2659_format_yuyv
,
806 .code
= MEDIA_BUS_FMT_UYVY8_2X8
,
807 .format_ctrl_regs
= ov2659_format_uyvy
,
809 .code
= MEDIA_BUS_FMT_RGB565_2X8_BE
,
810 .format_ctrl_regs
= ov2659_format_rgb565
,
812 .code
= MEDIA_BUS_FMT_SBGGR8_1X8
,
813 .format_ctrl_regs
= ov2659_format_bggr
,
817 static inline struct ov2659
*to_ov2659(struct v4l2_subdev
*sd
)
819 return container_of(sd
, struct ov2659
, sd
);
822 /* sensor register write */
823 static int ov2659_write(struct i2c_client
*client
, u16 reg
, u8 val
)
833 msg
.addr
= client
->addr
;
834 msg
.flags
= client
->flags
;
836 msg
.len
= sizeof(buf
);
838 ret
= i2c_transfer(client
->adapter
, &msg
, 1);
842 dev_dbg(&client
->dev
,
843 "ov2659 write reg(0x%x val:0x%x) failed !\n", reg
, val
);
848 /* sensor register read */
849 static int ov2659_read(struct i2c_client
*client
, u16 reg
, u8
*val
)
851 struct i2c_msg msg
[2];
858 msg
[0].addr
= client
->addr
;
859 msg
[0].flags
= client
->flags
;
861 msg
[0].len
= sizeof(buf
);
863 msg
[1].addr
= client
->addr
;
864 msg
[1].flags
= client
->flags
| I2C_M_RD
;
868 ret
= i2c_transfer(client
->adapter
, msg
, 2);
874 dev_dbg(&client
->dev
,
875 "ov2659 read reg(0x%x val:0x%x) failed !\n", reg
, *val
);
880 static int ov2659_write_array(struct i2c_client
*client
,
881 const struct sensor_register
*regs
)
885 for (i
= 0; ret
== 0 && regs
[i
].addr
; i
++)
886 ret
= ov2659_write(client
, regs
[i
].addr
, regs
[i
].value
);
891 static void ov2659_pll_calc_params(struct ov2659
*ov2659
)
893 const struct ov2659_platform_data
*pdata
= ov2659
->pdata
;
894 u8 ctrl1_reg
= 0, ctrl2_reg
= 0, ctrl3_reg
= 0;
895 struct i2c_client
*client
= ov2659
->client
;
896 unsigned int desired
= pdata
->link_frequency
;
897 u32 prediv
, postdiv
, mult
;
902 for (i
= 0; ctrl1
[i
].div
!= 0; i
++) {
903 postdiv
= ctrl1
[i
].div
;
904 for (j
= 0; ctrl3
[j
].div
!= 0; j
++) {
905 prediv
= ctrl3
[j
].div
;
906 for (mult
= 1; mult
<= 63; mult
++) {
907 actual
= ov2659
->xvclk_frequency
;
911 delta
= actual
- desired
;
914 if ((delta
< bestdelta
) || (bestdelta
== -1)) {
916 ctrl1_reg
= ctrl1
[i
].reg
;
918 ctrl3_reg
= ctrl3
[j
].reg
;
924 ov2659
->pll
.ctrl1
= ctrl1_reg
;
925 ov2659
->pll
.ctrl2
= ctrl2_reg
;
926 ov2659
->pll
.ctrl3
= ctrl3_reg
;
928 dev_dbg(&client
->dev
,
929 "Actual reg config: ctrl1_reg: %02x ctrl2_reg: %02x ctrl3_reg: %02x\n",
930 ctrl1_reg
, ctrl2_reg
, ctrl3_reg
);
933 static int ov2659_set_pixel_clock(struct ov2659
*ov2659
)
935 struct i2c_client
*client
= ov2659
->client
;
936 struct sensor_register pll_regs
[] = {
937 {REG_SC_PLL_CTRL1
, ov2659
->pll
.ctrl1
},
938 {REG_SC_PLL_CTRL2
, ov2659
->pll
.ctrl2
},
939 {REG_SC_PLL_CTRL3
, ov2659
->pll
.ctrl3
},
943 dev_dbg(&client
->dev
, "%s\n", __func__
);
945 return ov2659_write_array(client
, pll_regs
);
948 static void ov2659_get_default_format(struct v4l2_mbus_framefmt
*format
)
950 format
->width
= ov2659_framesizes
[2].width
;
951 format
->height
= ov2659_framesizes
[2].height
;
952 format
->colorspace
= V4L2_COLORSPACE_SRGB
;
953 format
->code
= ov2659_formats
[0].code
;
954 format
->field
= V4L2_FIELD_NONE
;
957 static void ov2659_set_streaming(struct ov2659
*ov2659
, int on
)
959 struct i2c_client
*client
= ov2659
->client
;
964 dev_dbg(&client
->dev
, "%s: on: %d\n", __func__
, on
);
966 ret
= ov2659_write(client
, REG_SOFTWARE_STANDBY
, on
);
968 dev_err(&client
->dev
, "ov2659 soft standby failed\n");
971 static int ov2659_init(struct v4l2_subdev
*sd
, u32 val
)
973 struct i2c_client
*client
= v4l2_get_subdevdata(sd
);
975 return ov2659_write_array(client
, ov2659_init_regs
);
979 * V4L2 subdev video and pad level operations
982 static int ov2659_enum_mbus_code(struct v4l2_subdev
*sd
,
983 struct v4l2_subdev_state
*sd_state
,
984 struct v4l2_subdev_mbus_code_enum
*code
)
986 struct i2c_client
*client
= v4l2_get_subdevdata(sd
);
988 dev_dbg(&client
->dev
, "%s:\n", __func__
);
990 if (code
->index
>= ARRAY_SIZE(ov2659_formats
))
993 code
->code
= ov2659_formats
[code
->index
].code
;
998 static int ov2659_enum_frame_sizes(struct v4l2_subdev
*sd
,
999 struct v4l2_subdev_state
*sd_state
,
1000 struct v4l2_subdev_frame_size_enum
*fse
)
1002 struct i2c_client
*client
= v4l2_get_subdevdata(sd
);
1003 int i
= ARRAY_SIZE(ov2659_formats
);
1005 dev_dbg(&client
->dev
, "%s:\n", __func__
);
1007 if (fse
->index
>= ARRAY_SIZE(ov2659_framesizes
))
1011 if (fse
->code
== ov2659_formats
[i
].code
)
1014 fse
->code
= ov2659_formats
[i
].code
;
1016 fse
->min_width
= ov2659_framesizes
[fse
->index
].width
;
1017 fse
->max_width
= fse
->min_width
;
1018 fse
->max_height
= ov2659_framesizes
[fse
->index
].height
;
1019 fse
->min_height
= fse
->max_height
;
1024 static int ov2659_get_fmt(struct v4l2_subdev
*sd
,
1025 struct v4l2_subdev_state
*sd_state
,
1026 struct v4l2_subdev_format
*fmt
)
1028 struct i2c_client
*client
= v4l2_get_subdevdata(sd
);
1029 struct ov2659
*ov2659
= to_ov2659(sd
);
1031 dev_dbg(&client
->dev
, "ov2659_get_fmt\n");
1033 if (fmt
->which
== V4L2_SUBDEV_FORMAT_TRY
) {
1034 struct v4l2_mbus_framefmt
*mf
;
1036 mf
= v4l2_subdev_state_get_format(sd_state
, 0);
1037 mutex_lock(&ov2659
->lock
);
1039 mutex_unlock(&ov2659
->lock
);
1043 mutex_lock(&ov2659
->lock
);
1044 fmt
->format
= ov2659
->format
;
1045 mutex_unlock(&ov2659
->lock
);
1047 dev_dbg(&client
->dev
, "ov2659_get_fmt: %x %dx%d\n",
1048 ov2659
->format
.code
, ov2659
->format
.width
,
1049 ov2659
->format
.height
);
1054 static void __ov2659_try_frame_size(struct v4l2_mbus_framefmt
*mf
,
1055 const struct ov2659_framesize
**size
)
1057 const struct ov2659_framesize
*fsize
= &ov2659_framesizes
[0];
1058 const struct ov2659_framesize
*match
= NULL
;
1059 int i
= ARRAY_SIZE(ov2659_framesizes
);
1060 unsigned int min_err
= UINT_MAX
;
1063 int err
= abs(fsize
->width
- mf
->width
)
1064 + abs(fsize
->height
- mf
->height
);
1065 if ((err
< min_err
) && (fsize
->regs
[0].addr
)) {
1073 match
= &ov2659_framesizes
[2];
1075 mf
->width
= match
->width
;
1076 mf
->height
= match
->height
;
1082 static int ov2659_set_fmt(struct v4l2_subdev
*sd
,
1083 struct v4l2_subdev_state
*sd_state
,
1084 struct v4l2_subdev_format
*fmt
)
1086 struct i2c_client
*client
= v4l2_get_subdevdata(sd
);
1087 int index
= ARRAY_SIZE(ov2659_formats
);
1088 struct v4l2_mbus_framefmt
*mf
= &fmt
->format
;
1089 const struct ov2659_framesize
*size
= NULL
;
1090 struct ov2659
*ov2659
= to_ov2659(sd
);
1093 dev_dbg(&client
->dev
, "ov2659_set_fmt\n");
1095 __ov2659_try_frame_size(mf
, &size
);
1097 while (--index
>= 0)
1098 if (ov2659_formats
[index
].code
== mf
->code
)
1103 mf
->code
= ov2659_formats
[index
].code
;
1106 mf
->colorspace
= V4L2_COLORSPACE_SRGB
;
1107 mf
->field
= V4L2_FIELD_NONE
;
1109 mutex_lock(&ov2659
->lock
);
1111 if (fmt
->which
== V4L2_SUBDEV_FORMAT_TRY
) {
1112 mf
= v4l2_subdev_state_get_format(sd_state
, fmt
->pad
);
1117 if (ov2659
->streaming
) {
1118 mutex_unlock(&ov2659
->lock
);
1122 ov2659
->frame_size
= size
;
1123 ov2659
->format
= fmt
->format
;
1124 ov2659
->format_ctrl_regs
=
1125 ov2659_formats
[index
].format_ctrl_regs
;
1127 if (ov2659
->format
.code
!= MEDIA_BUS_FMT_SBGGR8_1X8
)
1128 val
= ov2659
->pdata
->link_frequency
/ 2;
1130 val
= ov2659
->pdata
->link_frequency
;
1132 ret
= v4l2_ctrl_s_ctrl_int64(ov2659
->link_frequency
, val
);
1134 dev_warn(&client
->dev
,
1135 "failed to set link_frequency rate (%d)\n",
1139 mutex_unlock(&ov2659
->lock
);
1143 static int ov2659_set_frame_size(struct ov2659
*ov2659
)
1145 struct i2c_client
*client
= ov2659
->client
;
1147 dev_dbg(&client
->dev
, "%s\n", __func__
);
1149 return ov2659_write_array(ov2659
->client
, ov2659
->frame_size
->regs
);
1152 static int ov2659_set_format(struct ov2659
*ov2659
)
1154 struct i2c_client
*client
= ov2659
->client
;
1156 dev_dbg(&client
->dev
, "%s\n", __func__
);
1158 return ov2659_write_array(ov2659
->client
, ov2659
->format_ctrl_regs
);
1161 static int ov2659_s_stream(struct v4l2_subdev
*sd
, int on
)
1163 struct i2c_client
*client
= v4l2_get_subdevdata(sd
);
1164 struct ov2659
*ov2659
= to_ov2659(sd
);
1167 dev_dbg(&client
->dev
, "%s: on: %d\n", __func__
, on
);
1169 mutex_lock(&ov2659
->lock
);
1173 if (ov2659
->streaming
== on
)
1177 /* Stop Streaming Sequence */
1178 ov2659_set_streaming(ov2659
, 0);
1179 ov2659
->streaming
= on
;
1180 pm_runtime_put(&client
->dev
);
1184 ret
= pm_runtime_resume_and_get(&client
->dev
);
1188 ret
= ov2659_init(sd
, 0);
1190 ret
= ov2659_set_pixel_clock(ov2659
);
1192 ret
= ov2659_set_frame_size(ov2659
);
1194 ret
= ov2659_set_format(ov2659
);
1196 ov2659_set_streaming(ov2659
, 1);
1197 ov2659
->streaming
= on
;
1201 mutex_unlock(&ov2659
->lock
);
1205 static int ov2659_set_test_pattern(struct ov2659
*ov2659
, int value
)
1207 struct i2c_client
*client
= v4l2_get_subdevdata(&ov2659
->sd
);
1211 ret
= ov2659_read(client
, REG_PRE_ISP_CTRL00
, &val
);
1217 val
&= ~TEST_PATTERN_ENABLE
;
1220 val
&= VERTICAL_COLOR_BAR_MASK
;
1221 val
|= TEST_PATTERN_ENABLE
;
1225 return ov2659_write(client
, REG_PRE_ISP_CTRL00
, val
);
1228 static int ov2659_s_ctrl(struct v4l2_ctrl
*ctrl
)
1230 struct ov2659
*ov2659
=
1231 container_of(ctrl
->handler
, struct ov2659
, ctrls
);
1232 struct i2c_client
*client
= ov2659
->client
;
1234 /* V4L2 controls values will be applied only when power is already up */
1235 if (!pm_runtime_get_if_in_use(&client
->dev
))
1239 case V4L2_CID_TEST_PATTERN
:
1240 return ov2659_set_test_pattern(ov2659
, ctrl
->val
);
1243 pm_runtime_put(&client
->dev
);
1247 static const struct v4l2_ctrl_ops ov2659_ctrl_ops
= {
1248 .s_ctrl
= ov2659_s_ctrl
,
1251 static const char * const ov2659_test_pattern_menu
[] = {
1253 "Vertical Color Bars",
1256 static int ov2659_power_off(struct device
*dev
)
1258 struct i2c_client
*client
= to_i2c_client(dev
);
1259 struct v4l2_subdev
*sd
= i2c_get_clientdata(client
);
1260 struct ov2659
*ov2659
= to_ov2659(sd
);
1262 dev_dbg(&client
->dev
, "%s:\n", __func__
);
1264 gpiod_set_value(ov2659
->pwdn_gpio
, 1);
1266 clk_disable_unprepare(ov2659
->clk
);
1271 static int ov2659_power_on(struct device
*dev
)
1273 struct i2c_client
*client
= to_i2c_client(dev
);
1274 struct v4l2_subdev
*sd
= i2c_get_clientdata(client
);
1275 struct ov2659
*ov2659
= to_ov2659(sd
);
1278 dev_dbg(&client
->dev
, "%s:\n", __func__
);
1280 ret
= clk_prepare_enable(ov2659
->clk
);
1282 dev_err(&client
->dev
, "%s: failed to enable clock\n",
1287 gpiod_set_value(ov2659
->pwdn_gpio
, 0);
1289 if (ov2659
->resetb_gpio
) {
1290 gpiod_set_value(ov2659
->resetb_gpio
, 1);
1291 usleep_range(500, 1000);
1292 gpiod_set_value(ov2659
->resetb_gpio
, 0);
1293 usleep_range(3000, 5000);
1299 /* -----------------------------------------------------------------------------
1300 * V4L2 subdev internal operations
1303 static int ov2659_open(struct v4l2_subdev
*sd
, struct v4l2_subdev_fh
*fh
)
1305 struct i2c_client
*client
= v4l2_get_subdevdata(sd
);
1306 struct v4l2_mbus_framefmt
*format
=
1307 v4l2_subdev_state_get_format(fh
->state
, 0);
1309 dev_dbg(&client
->dev
, "%s:\n", __func__
);
1311 ov2659_get_default_format(format
);
1316 static const struct v4l2_subdev_core_ops ov2659_subdev_core_ops
= {
1317 .log_status
= v4l2_ctrl_subdev_log_status
,
1318 .subscribe_event
= v4l2_ctrl_subdev_subscribe_event
,
1319 .unsubscribe_event
= v4l2_event_subdev_unsubscribe
,
1322 static const struct v4l2_subdev_video_ops ov2659_subdev_video_ops
= {
1323 .s_stream
= ov2659_s_stream
,
1326 static const struct v4l2_subdev_pad_ops ov2659_subdev_pad_ops
= {
1327 .enum_mbus_code
= ov2659_enum_mbus_code
,
1328 .enum_frame_size
= ov2659_enum_frame_sizes
,
1329 .get_fmt
= ov2659_get_fmt
,
1330 .set_fmt
= ov2659_set_fmt
,
1333 static const struct v4l2_subdev_ops ov2659_subdev_ops
= {
1334 .core
= &ov2659_subdev_core_ops
,
1335 .video
= &ov2659_subdev_video_ops
,
1336 .pad
= &ov2659_subdev_pad_ops
,
1339 static const struct v4l2_subdev_internal_ops ov2659_subdev_internal_ops
= {
1340 .open
= ov2659_open
,
1343 static int ov2659_detect(struct v4l2_subdev
*sd
)
1345 struct i2c_client
*client
= v4l2_get_subdevdata(sd
);
1350 dev_dbg(&client
->dev
, "%s:\n", __func__
);
1352 ret
= ov2659_write(client
, REG_SOFTWARE_RESET
, 0x01);
1354 dev_err(&client
->dev
, "Sensor soft reset failed\n");
1357 usleep_range(1000, 2000);
1359 /* Check sensor revision */
1360 ret
= ov2659_read(client
, REG_SC_CHIP_ID_H
, &pid
);
1362 ret
= ov2659_read(client
, REG_SC_CHIP_ID_L
, &ver
);
1367 id
= OV265X_ID(pid
, ver
);
1368 if (id
!= OV2659_ID
) {
1369 dev_err(&client
->dev
,
1370 "Sensor detection failed (%04X)\n", id
);
1373 dev_info(&client
->dev
, "Found OV%04X sensor\n", id
);
1380 static struct ov2659_platform_data
*
1381 ov2659_get_pdata(struct i2c_client
*client
)
1383 struct ov2659_platform_data
*pdata
;
1384 struct v4l2_fwnode_endpoint bus_cfg
= { .bus_type
= 0 };
1385 struct device_node
*endpoint
;
1388 if (!IS_ENABLED(CONFIG_OF
) || !client
->dev
.of_node
)
1389 return client
->dev
.platform_data
;
1391 endpoint
= of_graph_get_endpoint_by_regs(client
->dev
.of_node
, 0, -1);
1395 ret
= v4l2_fwnode_endpoint_alloc_parse(of_fwnode_handle(endpoint
),
1402 pdata
= devm_kzalloc(&client
->dev
, sizeof(*pdata
), GFP_KERNEL
);
1406 if (!bus_cfg
.nr_of_link_frequencies
) {
1407 dev_err(&client
->dev
,
1408 "link-frequencies property not found or too many\n");
1413 pdata
->link_frequency
= bus_cfg
.link_frequencies
[0];
1416 v4l2_fwnode_endpoint_free(&bus_cfg
);
1417 of_node_put(endpoint
);
1421 static int ov2659_probe(struct i2c_client
*client
)
1423 const struct ov2659_platform_data
*pdata
= ov2659_get_pdata(client
);
1424 struct v4l2_subdev
*sd
;
1425 struct ov2659
*ov2659
;
1429 dev_err(&client
->dev
, "platform data not specified\n");
1433 ov2659
= devm_kzalloc(&client
->dev
, sizeof(*ov2659
), GFP_KERNEL
);
1437 ov2659
->pdata
= pdata
;
1438 ov2659
->client
= client
;
1440 ov2659
->clk
= devm_clk_get(&client
->dev
, "xvclk");
1441 if (IS_ERR(ov2659
->clk
))
1442 return PTR_ERR(ov2659
->clk
);
1444 ov2659
->xvclk_frequency
= clk_get_rate(ov2659
->clk
);
1445 if (ov2659
->xvclk_frequency
< 6000000 ||
1446 ov2659
->xvclk_frequency
> 27000000)
1449 /* Optional gpio don't fail if not present */
1450 ov2659
->pwdn_gpio
= devm_gpiod_get_optional(&client
->dev
, "powerdown",
1452 if (IS_ERR(ov2659
->pwdn_gpio
))
1453 return PTR_ERR(ov2659
->pwdn_gpio
);
1455 /* Optional gpio don't fail if not present */
1456 ov2659
->resetb_gpio
= devm_gpiod_get_optional(&client
->dev
, "reset",
1458 if (IS_ERR(ov2659
->resetb_gpio
))
1459 return PTR_ERR(ov2659
->resetb_gpio
);
1461 v4l2_ctrl_handler_init(&ov2659
->ctrls
, 2);
1462 ov2659
->link_frequency
=
1463 v4l2_ctrl_new_std(&ov2659
->ctrls
, &ov2659_ctrl_ops
,
1464 V4L2_CID_PIXEL_RATE
,
1465 pdata
->link_frequency
/ 2,
1466 pdata
->link_frequency
, 1,
1467 pdata
->link_frequency
);
1468 v4l2_ctrl_new_std_menu_items(&ov2659
->ctrls
, &ov2659_ctrl_ops
,
1469 V4L2_CID_TEST_PATTERN
,
1470 ARRAY_SIZE(ov2659_test_pattern_menu
) - 1,
1471 0, 0, ov2659_test_pattern_menu
);
1472 ov2659
->sd
.ctrl_handler
= &ov2659
->ctrls
;
1474 if (ov2659
->ctrls
.error
) {
1475 dev_err(&client
->dev
, "%s: control initialization error %d\n",
1476 __func__
, ov2659
->ctrls
.error
);
1477 return ov2659
->ctrls
.error
;
1481 client
->flags
|= I2C_CLIENT_SCCB
;
1483 v4l2_i2c_subdev_init(sd
, client
, &ov2659_subdev_ops
);
1484 sd
->internal_ops
= &ov2659_subdev_internal_ops
;
1485 sd
->flags
|= V4L2_SUBDEV_FL_HAS_DEVNODE
|
1486 V4L2_SUBDEV_FL_HAS_EVENTS
;
1488 ov2659
->pad
.flags
= MEDIA_PAD_FL_SOURCE
;
1489 sd
->entity
.function
= MEDIA_ENT_F_CAM_SENSOR
;
1490 ret
= media_entity_pads_init(&sd
->entity
, 1, &ov2659
->pad
);
1492 v4l2_ctrl_handler_free(&ov2659
->ctrls
);
1496 mutex_init(&ov2659
->lock
);
1498 ov2659_get_default_format(&ov2659
->format
);
1499 ov2659
->frame_size
= &ov2659_framesizes
[2];
1500 ov2659
->format_ctrl_regs
= ov2659_formats
[0].format_ctrl_regs
;
1502 ret
= ov2659_power_on(&client
->dev
);
1506 ret
= ov2659_detect(sd
);
1510 /* Calculate the PLL register value needed */
1511 ov2659_pll_calc_params(ov2659
);
1513 ret
= v4l2_async_register_subdev(&ov2659
->sd
);
1517 dev_info(&client
->dev
, "%s sensor driver registered !!\n", sd
->name
);
1519 pm_runtime_set_active(&client
->dev
);
1520 pm_runtime_enable(&client
->dev
);
1521 pm_runtime_idle(&client
->dev
);
1526 v4l2_ctrl_handler_free(&ov2659
->ctrls
);
1527 ov2659_power_off(&client
->dev
);
1528 media_entity_cleanup(&sd
->entity
);
1529 mutex_destroy(&ov2659
->lock
);
1533 static void ov2659_remove(struct i2c_client
*client
)
1535 struct v4l2_subdev
*sd
= i2c_get_clientdata(client
);
1536 struct ov2659
*ov2659
= to_ov2659(sd
);
1538 v4l2_ctrl_handler_free(&ov2659
->ctrls
);
1539 v4l2_async_unregister_subdev(sd
);
1540 media_entity_cleanup(&sd
->entity
);
1541 mutex_destroy(&ov2659
->lock
);
1543 pm_runtime_disable(&client
->dev
);
1544 if (!pm_runtime_status_suspended(&client
->dev
))
1545 ov2659_power_off(&client
->dev
);
1546 pm_runtime_set_suspended(&client
->dev
);
1549 static const struct dev_pm_ops ov2659_pm_ops
= {
1550 SET_RUNTIME_PM_OPS(ov2659_power_off
, ov2659_power_on
, NULL
)
1553 static const struct i2c_device_id ov2659_id
[] = {
1557 MODULE_DEVICE_TABLE(i2c
, ov2659_id
);
1559 #if IS_ENABLED(CONFIG_OF)
1560 static const struct of_device_id ov2659_of_match
[] = {
1561 { .compatible
= "ovti,ov2659", },
1564 MODULE_DEVICE_TABLE(of
, ov2659_of_match
);
1567 static struct i2c_driver ov2659_i2c_driver
= {
1569 .name
= DRIVER_NAME
,
1570 .pm
= &ov2659_pm_ops
,
1571 .of_match_table
= of_match_ptr(ov2659_of_match
),
1573 .probe
= ov2659_probe
,
1574 .remove
= ov2659_remove
,
1575 .id_table
= ov2659_id
,
1578 module_i2c_driver(ov2659_i2c_driver
);
1580 MODULE_AUTHOR("Benoit Parrot <bparrot@ti.com>");
1581 MODULE_DESCRIPTION("OV2659 CMOS Image Sensor driver");
1582 MODULE_LICENSE("GPL v2");