2 * adv7180.c Analog Devices ADV7180 video decoder driver
3 * Copyright (c) 2009 Intel Corporation
4 * Copyright (C) 2013 Cogent Embedded, Inc.
5 * Copyright (C) 2013 Renesas Solutions Corp.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include <linux/module.h>
22 #include <linux/init.h>
23 #include <linux/errno.h>
24 #include <linux/kernel.h>
25 #include <linux/interrupt.h>
26 #include <linux/i2c.h>
27 #include <linux/slab.h>
29 #include <linux/videodev2.h>
30 #include <media/v4l2-ioctl.h>
31 #include <media/v4l2-event.h>
32 #include <media/v4l2-device.h>
33 #include <media/v4l2-ctrls.h>
34 #include <linux/mutex.h>
35 #include <linux/delay.h>
37 #define ADV7180_STD_AD_PAL_BG_NTSC_J_SECAM 0x0
38 #define ADV7180_STD_AD_PAL_BG_NTSC_J_SECAM_PED 0x1
39 #define ADV7180_STD_AD_PAL_N_NTSC_J_SECAM 0x2
40 #define ADV7180_STD_AD_PAL_N_NTSC_M_SECAM 0x3
41 #define ADV7180_STD_NTSC_J 0x4
42 #define ADV7180_STD_NTSC_M 0x5
43 #define ADV7180_STD_PAL60 0x6
44 #define ADV7180_STD_NTSC_443 0x7
45 #define ADV7180_STD_PAL_BG 0x8
46 #define ADV7180_STD_PAL_N 0x9
47 #define ADV7180_STD_PAL_M 0xa
48 #define ADV7180_STD_PAL_M_PED 0xb
49 #define ADV7180_STD_PAL_COMB_N 0xc
50 #define ADV7180_STD_PAL_COMB_N_PED 0xd
51 #define ADV7180_STD_PAL_SECAM 0xe
52 #define ADV7180_STD_PAL_SECAM_PED 0xf
54 #define ADV7180_REG_INPUT_CONTROL 0x0000
55 #define ADV7180_INPUT_CONTROL_INSEL_MASK 0x0f
57 #define ADV7182_REG_INPUT_VIDSEL 0x0002
59 #define ADV7180_REG_EXTENDED_OUTPUT_CONTROL 0x0004
60 #define ADV7180_EXTENDED_OUTPUT_CONTROL_NTSCDIS 0xC5
62 #define ADV7180_REG_AUTODETECT_ENABLE 0x07
63 #define ADV7180_AUTODETECT_DEFAULT 0x7f
65 #define ADV7180_REG_CON 0x0008 /*Unsigned */
66 #define ADV7180_CON_MIN 0
67 #define ADV7180_CON_DEF 128
68 #define ADV7180_CON_MAX 255
70 #define ADV7180_REG_BRI 0x000a /*Signed */
71 #define ADV7180_BRI_MIN -128
72 #define ADV7180_BRI_DEF 0
73 #define ADV7180_BRI_MAX 127
75 #define ADV7180_REG_HUE 0x000b /*Signed, inverted */
76 #define ADV7180_HUE_MIN -127
77 #define ADV7180_HUE_DEF 0
78 #define ADV7180_HUE_MAX 128
80 #define ADV7180_REG_CTRL 0x000e
81 #define ADV7180_CTRL_IRQ_SPACE 0x20
83 #define ADV7180_REG_PWR_MAN 0x0f
84 #define ADV7180_PWR_MAN_ON 0x04
85 #define ADV7180_PWR_MAN_OFF 0x24
86 #define ADV7180_PWR_MAN_RES 0x80
88 #define ADV7180_REG_STATUS1 0x0010
89 #define ADV7180_STATUS1_IN_LOCK 0x01
90 #define ADV7180_STATUS1_AUTOD_MASK 0x70
91 #define ADV7180_STATUS1_AUTOD_NTSM_M_J 0x00
92 #define ADV7180_STATUS1_AUTOD_NTSC_4_43 0x10
93 #define ADV7180_STATUS1_AUTOD_PAL_M 0x20
94 #define ADV7180_STATUS1_AUTOD_PAL_60 0x30
95 #define ADV7180_STATUS1_AUTOD_PAL_B_G 0x40
96 #define ADV7180_STATUS1_AUTOD_SECAM 0x50
97 #define ADV7180_STATUS1_AUTOD_PAL_COMB 0x60
98 #define ADV7180_STATUS1_AUTOD_SECAM_525 0x70
100 #define ADV7180_REG_IDENT 0x0011
101 #define ADV7180_ID_7180 0x18
103 #define ADV7180_REG_ICONF1 0x2040
104 #define ADV7180_ICONF1_ACTIVE_LOW 0x01
105 #define ADV7180_ICONF1_PSYNC_ONLY 0x10
106 #define ADV7180_ICONF1_ACTIVE_TO_CLR 0xC0
108 #define ADV7180_REG_SD_SAT_CB 0x00e3 /*Unsigned */
109 #define ADV7180_REG_SD_SAT_CR 0x00e4 /*Unsigned */
110 #define ADV7180_SAT_MIN 0
111 #define ADV7180_SAT_DEF 128
112 #define ADV7180_SAT_MAX 255
114 #define ADV7180_IRQ1_LOCK 0x01
115 #define ADV7180_IRQ1_UNLOCK 0x02
116 #define ADV7180_REG_ISR1 0x2042
117 #define ADV7180_REG_ICR1 0x2043
118 #define ADV7180_REG_IMR1 0x2044
119 #define ADV7180_REG_IMR2 0x2048
120 #define ADV7180_IRQ3_AD_CHANGE 0x08
121 #define ADV7180_REG_ISR3 0x204A
122 #define ADV7180_REG_ICR3 0x204B
123 #define ADV7180_REG_IMR3 0x204C
124 #define ADV7180_REG_IMR4 0x2050
126 #define ADV7180_REG_NTSC_V_BIT_END 0x00E6
127 #define ADV7180_NTSC_V_BIT_END_MANUAL_NVEND 0x4F
129 #define ADV7180_REG_VPP_SLAVE_ADDR 0xFD
130 #define ADV7180_REG_CSI_SLAVE_ADDR 0xFE
132 #define ADV7180_REG_FLCONTROL 0x40e0
133 #define ADV7180_FLCONTROL_FL_ENABLE 0x1
135 #define ADV7180_CSI_REG_PWRDN 0x00
136 #define ADV7180_CSI_PWRDN 0x80
138 #define ADV7180_INPUT_CVBS_AIN1 0x00
139 #define ADV7180_INPUT_CVBS_AIN2 0x01
140 #define ADV7180_INPUT_CVBS_AIN3 0x02
141 #define ADV7180_INPUT_CVBS_AIN4 0x03
142 #define ADV7180_INPUT_CVBS_AIN5 0x04
143 #define ADV7180_INPUT_CVBS_AIN6 0x05
144 #define ADV7180_INPUT_SVIDEO_AIN1_AIN2 0x06
145 #define ADV7180_INPUT_SVIDEO_AIN3_AIN4 0x07
146 #define ADV7180_INPUT_SVIDEO_AIN5_AIN6 0x08
147 #define ADV7180_INPUT_YPRPB_AIN1_AIN2_AIN3 0x09
148 #define ADV7180_INPUT_YPRPB_AIN4_AIN5_AIN6 0x0a
150 #define ADV7182_INPUT_CVBS_AIN1 0x00
151 #define ADV7182_INPUT_CVBS_AIN2 0x01
152 #define ADV7182_INPUT_CVBS_AIN3 0x02
153 #define ADV7182_INPUT_CVBS_AIN4 0x03
154 #define ADV7182_INPUT_CVBS_AIN5 0x04
155 #define ADV7182_INPUT_CVBS_AIN6 0x05
156 #define ADV7182_INPUT_CVBS_AIN7 0x06
157 #define ADV7182_INPUT_CVBS_AIN8 0x07
158 #define ADV7182_INPUT_SVIDEO_AIN1_AIN2 0x08
159 #define ADV7182_INPUT_SVIDEO_AIN3_AIN4 0x09
160 #define ADV7182_INPUT_SVIDEO_AIN5_AIN6 0x0a
161 #define ADV7182_INPUT_SVIDEO_AIN7_AIN8 0x0b
162 #define ADV7182_INPUT_YPRPB_AIN1_AIN2_AIN3 0x0c
163 #define ADV7182_INPUT_YPRPB_AIN4_AIN5_AIN6 0x0d
164 #define ADV7182_INPUT_DIFF_CVBS_AIN1_AIN2 0x0e
165 #define ADV7182_INPUT_DIFF_CVBS_AIN3_AIN4 0x0f
166 #define ADV7182_INPUT_DIFF_CVBS_AIN5_AIN6 0x10
167 #define ADV7182_INPUT_DIFF_CVBS_AIN7_AIN8 0x11
169 #define ADV7180_DEFAULT_CSI_I2C_ADDR 0x44
170 #define ADV7180_DEFAULT_VPP_I2C_ADDR 0x42
172 #define V4L2_CID_ADV_FAST_SWITCH (V4L2_CID_USER_ADV7180_BASE + 0x00)
174 struct adv7180_state
;
176 #define ADV7180_FLAG_RESET_POWERED BIT(0)
177 #define ADV7180_FLAG_V2 BIT(1)
178 #define ADV7180_FLAG_MIPI_CSI2 BIT(2)
179 #define ADV7180_FLAG_I2P BIT(3)
181 struct adv7180_chip_info
{
183 unsigned int valid_input_mask
;
184 int (*set_std
)(struct adv7180_state
*st
, unsigned int std
);
185 int (*select_input
)(struct adv7180_state
*st
, unsigned int input
);
186 int (*init
)(struct adv7180_state
*state
);
189 struct adv7180_state
{
190 struct v4l2_ctrl_handler ctrl_hdl
;
191 struct v4l2_subdev sd
;
192 struct media_pad pad
;
193 struct mutex mutex
; /* mutual excl. when accessing chip */
195 v4l2_std_id curr_norm
;
200 struct i2c_client
*client
;
201 unsigned int register_page
;
202 struct i2c_client
*csi_client
;
203 struct i2c_client
*vpp_client
;
204 const struct adv7180_chip_info
*chip_info
;
205 enum v4l2_field field
;
207 #define to_adv7180_sd(_ctrl) (&container_of(_ctrl->handler, \
208 struct adv7180_state, \
211 static int adv7180_select_page(struct adv7180_state
*state
, unsigned int page
)
213 if (state
->register_page
!= page
) {
214 i2c_smbus_write_byte_data(state
->client
, ADV7180_REG_CTRL
,
216 state
->register_page
= page
;
222 static int adv7180_write(struct adv7180_state
*state
, unsigned int reg
,
225 lockdep_assert_held(&state
->mutex
);
226 adv7180_select_page(state
, reg
>> 8);
227 return i2c_smbus_write_byte_data(state
->client
, reg
& 0xff, value
);
230 static int adv7180_read(struct adv7180_state
*state
, unsigned int reg
)
232 lockdep_assert_held(&state
->mutex
);
233 adv7180_select_page(state
, reg
>> 8);
234 return i2c_smbus_read_byte_data(state
->client
, reg
& 0xff);
237 static int adv7180_csi_write(struct adv7180_state
*state
, unsigned int reg
,
240 return i2c_smbus_write_byte_data(state
->csi_client
, reg
, value
);
243 static int adv7180_set_video_standard(struct adv7180_state
*state
,
246 return state
->chip_info
->set_std(state
, std
);
249 static int adv7180_vpp_write(struct adv7180_state
*state
, unsigned int reg
,
252 return i2c_smbus_write_byte_data(state
->vpp_client
, reg
, value
);
255 static v4l2_std_id
adv7180_std_to_v4l2(u8 status1
)
257 /* in case V4L2_IN_ST_NO_SIGNAL */
258 if (!(status1
& ADV7180_STATUS1_IN_LOCK
))
259 return V4L2_STD_UNKNOWN
;
261 switch (status1
& ADV7180_STATUS1_AUTOD_MASK
) {
262 case ADV7180_STATUS1_AUTOD_NTSM_M_J
:
263 return V4L2_STD_NTSC
;
264 case ADV7180_STATUS1_AUTOD_NTSC_4_43
:
265 return V4L2_STD_NTSC_443
;
266 case ADV7180_STATUS1_AUTOD_PAL_M
:
267 return V4L2_STD_PAL_M
;
268 case ADV7180_STATUS1_AUTOD_PAL_60
:
269 return V4L2_STD_PAL_60
;
270 case ADV7180_STATUS1_AUTOD_PAL_B_G
:
272 case ADV7180_STATUS1_AUTOD_SECAM
:
273 return V4L2_STD_SECAM
;
274 case ADV7180_STATUS1_AUTOD_PAL_COMB
:
275 return V4L2_STD_PAL_Nc
| V4L2_STD_PAL_N
;
276 case ADV7180_STATUS1_AUTOD_SECAM_525
:
277 return V4L2_STD_SECAM
;
279 return V4L2_STD_UNKNOWN
;
283 static int v4l2_std_to_adv7180(v4l2_std_id std
)
285 if (std
== V4L2_STD_PAL_60
)
286 return ADV7180_STD_PAL60
;
287 if (std
== V4L2_STD_NTSC_443
)
288 return ADV7180_STD_NTSC_443
;
289 if (std
== V4L2_STD_PAL_N
)
290 return ADV7180_STD_PAL_N
;
291 if (std
== V4L2_STD_PAL_M
)
292 return ADV7180_STD_PAL_M
;
293 if (std
== V4L2_STD_PAL_Nc
)
294 return ADV7180_STD_PAL_COMB_N
;
296 if (std
& V4L2_STD_PAL
)
297 return ADV7180_STD_PAL_BG
;
298 if (std
& V4L2_STD_NTSC
)
299 return ADV7180_STD_NTSC_M
;
300 if (std
& V4L2_STD_SECAM
)
301 return ADV7180_STD_PAL_SECAM
;
306 static u32
adv7180_status_to_v4l2(u8 status1
)
308 if (!(status1
& ADV7180_STATUS1_IN_LOCK
))
309 return V4L2_IN_ST_NO_SIGNAL
;
314 static int __adv7180_status(struct adv7180_state
*state
, u32
*status
,
317 int status1
= adv7180_read(state
, ADV7180_REG_STATUS1
);
323 *status
= adv7180_status_to_v4l2(status1
);
325 *std
= adv7180_std_to_v4l2(status1
);
330 static inline struct adv7180_state
*to_state(struct v4l2_subdev
*sd
)
332 return container_of(sd
, struct adv7180_state
, sd
);
335 static int adv7180_querystd(struct v4l2_subdev
*sd
, v4l2_std_id
*std
)
337 struct adv7180_state
*state
= to_state(sd
);
338 int err
= mutex_lock_interruptible(&state
->mutex
);
342 if (state
->streaming
) {
347 err
= adv7180_set_video_standard(state
,
348 ADV7180_STD_AD_PAL_BG_NTSC_J_SECAM
);
353 __adv7180_status(state
, NULL
, std
);
355 err
= v4l2_std_to_adv7180(state
->curr_norm
);
359 err
= adv7180_set_video_standard(state
, err
);
362 mutex_unlock(&state
->mutex
);
366 static int adv7180_s_routing(struct v4l2_subdev
*sd
, u32 input
,
367 u32 output
, u32 config
)
369 struct adv7180_state
*state
= to_state(sd
);
370 int ret
= mutex_lock_interruptible(&state
->mutex
);
375 if (input
> 31 || !(BIT(input
) & state
->chip_info
->valid_input_mask
)) {
380 ret
= state
->chip_info
->select_input(state
, input
);
383 state
->input
= input
;
385 mutex_unlock(&state
->mutex
);
389 static int adv7180_g_input_status(struct v4l2_subdev
*sd
, u32
*status
)
391 struct adv7180_state
*state
= to_state(sd
);
392 int ret
= mutex_lock_interruptible(&state
->mutex
);
396 ret
= __adv7180_status(state
, status
, NULL
);
397 mutex_unlock(&state
->mutex
);
401 static int adv7180_program_std(struct adv7180_state
*state
)
405 ret
= v4l2_std_to_adv7180(state
->curr_norm
);
409 ret
= adv7180_set_video_standard(state
, ret
);
415 static int adv7180_s_std(struct v4l2_subdev
*sd
, v4l2_std_id std
)
417 struct adv7180_state
*state
= to_state(sd
);
418 int ret
= mutex_lock_interruptible(&state
->mutex
);
423 /* Make sure we can support this std */
424 ret
= v4l2_std_to_adv7180(std
);
428 state
->curr_norm
= std
;
430 ret
= adv7180_program_std(state
);
432 mutex_unlock(&state
->mutex
);
436 static int adv7180_g_std(struct v4l2_subdev
*sd
, v4l2_std_id
*norm
)
438 struct adv7180_state
*state
= to_state(sd
);
440 *norm
= state
->curr_norm
;
445 static int adv7180_set_power(struct adv7180_state
*state
, bool on
)
451 val
= ADV7180_PWR_MAN_ON
;
453 val
= ADV7180_PWR_MAN_OFF
;
455 ret
= adv7180_write(state
, ADV7180_REG_PWR_MAN
, val
);
459 if (state
->chip_info
->flags
& ADV7180_FLAG_MIPI_CSI2
) {
461 adv7180_csi_write(state
, 0xDE, 0x02);
462 adv7180_csi_write(state
, 0xD2, 0xF7);
463 adv7180_csi_write(state
, 0xD8, 0x65);
464 adv7180_csi_write(state
, 0xE0, 0x09);
465 adv7180_csi_write(state
, 0x2C, 0x00);
466 if (state
->field
== V4L2_FIELD_NONE
)
467 adv7180_csi_write(state
, 0x1D, 0x80);
468 adv7180_csi_write(state
, 0x00, 0x00);
470 adv7180_csi_write(state
, 0x00, 0x80);
477 static int adv7180_s_power(struct v4l2_subdev
*sd
, int on
)
479 struct adv7180_state
*state
= to_state(sd
);
482 ret
= mutex_lock_interruptible(&state
->mutex
);
486 ret
= adv7180_set_power(state
, on
);
490 mutex_unlock(&state
->mutex
);
494 static int adv7180_s_ctrl(struct v4l2_ctrl
*ctrl
)
496 struct v4l2_subdev
*sd
= to_adv7180_sd(ctrl
);
497 struct adv7180_state
*state
= to_state(sd
);
498 int ret
= mutex_lock_interruptible(&state
->mutex
);
505 case V4L2_CID_BRIGHTNESS
:
506 ret
= adv7180_write(state
, ADV7180_REG_BRI
, val
);
509 /*Hue is inverted according to HSL chart */
510 ret
= adv7180_write(state
, ADV7180_REG_HUE
, -val
);
512 case V4L2_CID_CONTRAST
:
513 ret
= adv7180_write(state
, ADV7180_REG_CON
, val
);
515 case V4L2_CID_SATURATION
:
517 *This could be V4L2_CID_BLUE_BALANCE/V4L2_CID_RED_BALANCE
518 *Let's not confuse the user, everybody understands saturation
520 ret
= adv7180_write(state
, ADV7180_REG_SD_SAT_CB
, val
);
523 ret
= adv7180_write(state
, ADV7180_REG_SD_SAT_CR
, val
);
525 case V4L2_CID_ADV_FAST_SWITCH
:
527 /* ADI required write */
528 adv7180_write(state
, 0x80d9, 0x44);
529 adv7180_write(state
, ADV7180_REG_FLCONTROL
,
530 ADV7180_FLCONTROL_FL_ENABLE
);
532 /* ADI required write */
533 adv7180_write(state
, 0x80d9, 0xc4);
534 adv7180_write(state
, ADV7180_REG_FLCONTROL
, 0x00);
541 mutex_unlock(&state
->mutex
);
545 static const struct v4l2_ctrl_ops adv7180_ctrl_ops
= {
546 .s_ctrl
= adv7180_s_ctrl
,
549 static const struct v4l2_ctrl_config adv7180_ctrl_fast_switch
= {
550 .ops
= &adv7180_ctrl_ops
,
551 .id
= V4L2_CID_ADV_FAST_SWITCH
,
552 .name
= "Fast Switching",
553 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
559 static int adv7180_init_controls(struct adv7180_state
*state
)
561 v4l2_ctrl_handler_init(&state
->ctrl_hdl
, 4);
563 v4l2_ctrl_new_std(&state
->ctrl_hdl
, &adv7180_ctrl_ops
,
564 V4L2_CID_BRIGHTNESS
, ADV7180_BRI_MIN
,
565 ADV7180_BRI_MAX
, 1, ADV7180_BRI_DEF
);
566 v4l2_ctrl_new_std(&state
->ctrl_hdl
, &adv7180_ctrl_ops
,
567 V4L2_CID_CONTRAST
, ADV7180_CON_MIN
,
568 ADV7180_CON_MAX
, 1, ADV7180_CON_DEF
);
569 v4l2_ctrl_new_std(&state
->ctrl_hdl
, &adv7180_ctrl_ops
,
570 V4L2_CID_SATURATION
, ADV7180_SAT_MIN
,
571 ADV7180_SAT_MAX
, 1, ADV7180_SAT_DEF
);
572 v4l2_ctrl_new_std(&state
->ctrl_hdl
, &adv7180_ctrl_ops
,
573 V4L2_CID_HUE
, ADV7180_HUE_MIN
,
574 ADV7180_HUE_MAX
, 1, ADV7180_HUE_DEF
);
575 v4l2_ctrl_new_custom(&state
->ctrl_hdl
, &adv7180_ctrl_fast_switch
, NULL
);
577 state
->sd
.ctrl_handler
= &state
->ctrl_hdl
;
578 if (state
->ctrl_hdl
.error
) {
579 int err
= state
->ctrl_hdl
.error
;
581 v4l2_ctrl_handler_free(&state
->ctrl_hdl
);
584 v4l2_ctrl_handler_setup(&state
->ctrl_hdl
);
588 static void adv7180_exit_controls(struct adv7180_state
*state
)
590 v4l2_ctrl_handler_free(&state
->ctrl_hdl
);
593 static int adv7180_enum_mbus_code(struct v4l2_subdev
*sd
,
594 struct v4l2_subdev_pad_config
*cfg
,
595 struct v4l2_subdev_mbus_code_enum
*code
)
597 if (code
->index
!= 0)
600 code
->code
= MEDIA_BUS_FMT_YUYV8_2X8
;
605 static int adv7180_mbus_fmt(struct v4l2_subdev
*sd
,
606 struct v4l2_mbus_framefmt
*fmt
)
608 struct adv7180_state
*state
= to_state(sd
);
610 fmt
->code
= MEDIA_BUS_FMT_YUYV8_2X8
;
611 fmt
->colorspace
= V4L2_COLORSPACE_SMPTE170M
;
613 fmt
->height
= state
->curr_norm
& V4L2_STD_525_60
? 480 : 576;
618 static int adv7180_set_field_mode(struct adv7180_state
*state
)
620 if (!(state
->chip_info
->flags
& ADV7180_FLAG_I2P
))
623 if (state
->field
== V4L2_FIELD_NONE
) {
624 if (state
->chip_info
->flags
& ADV7180_FLAG_MIPI_CSI2
) {
625 adv7180_csi_write(state
, 0x01, 0x20);
626 adv7180_csi_write(state
, 0x02, 0x28);
627 adv7180_csi_write(state
, 0x03, 0x38);
628 adv7180_csi_write(state
, 0x04, 0x30);
629 adv7180_csi_write(state
, 0x05, 0x30);
630 adv7180_csi_write(state
, 0x06, 0x80);
631 adv7180_csi_write(state
, 0x07, 0x70);
632 adv7180_csi_write(state
, 0x08, 0x50);
634 adv7180_vpp_write(state
, 0xa3, 0x00);
635 adv7180_vpp_write(state
, 0x5b, 0x00);
636 adv7180_vpp_write(state
, 0x55, 0x80);
638 if (state
->chip_info
->flags
& ADV7180_FLAG_MIPI_CSI2
) {
639 adv7180_csi_write(state
, 0x01, 0x18);
640 adv7180_csi_write(state
, 0x02, 0x18);
641 adv7180_csi_write(state
, 0x03, 0x30);
642 adv7180_csi_write(state
, 0x04, 0x20);
643 adv7180_csi_write(state
, 0x05, 0x28);
644 adv7180_csi_write(state
, 0x06, 0x40);
645 adv7180_csi_write(state
, 0x07, 0x58);
646 adv7180_csi_write(state
, 0x08, 0x30);
648 adv7180_vpp_write(state
, 0xa3, 0x70);
649 adv7180_vpp_write(state
, 0x5b, 0x80);
650 adv7180_vpp_write(state
, 0x55, 0x00);
656 static int adv7180_get_pad_format(struct v4l2_subdev
*sd
,
657 struct v4l2_subdev_pad_config
*cfg
,
658 struct v4l2_subdev_format
*format
)
660 struct adv7180_state
*state
= to_state(sd
);
662 if (format
->which
== V4L2_SUBDEV_FORMAT_TRY
) {
663 format
->format
= *v4l2_subdev_get_try_format(sd
, cfg
, 0);
665 adv7180_mbus_fmt(sd
, &format
->format
);
666 format
->format
.field
= state
->field
;
672 static int adv7180_set_pad_format(struct v4l2_subdev
*sd
,
673 struct v4l2_subdev_pad_config
*cfg
,
674 struct v4l2_subdev_format
*format
)
676 struct adv7180_state
*state
= to_state(sd
);
677 struct v4l2_mbus_framefmt
*framefmt
;
679 switch (format
->format
.field
) {
680 case V4L2_FIELD_NONE
:
681 if (!(state
->chip_info
->flags
& ADV7180_FLAG_I2P
))
682 format
->format
.field
= V4L2_FIELD_INTERLACED
;
685 format
->format
.field
= V4L2_FIELD_INTERLACED
;
689 if (format
->which
== V4L2_SUBDEV_FORMAT_ACTIVE
) {
690 framefmt
= &format
->format
;
691 if (state
->field
!= format
->format
.field
) {
692 state
->field
= format
->format
.field
;
693 adv7180_set_power(state
, false);
694 adv7180_set_field_mode(state
);
695 adv7180_set_power(state
, true);
698 framefmt
= v4l2_subdev_get_try_format(sd
, cfg
, 0);
699 *framefmt
= format
->format
;
702 return adv7180_mbus_fmt(sd
, framefmt
);
705 static int adv7180_g_mbus_config(struct v4l2_subdev
*sd
,
706 struct v4l2_mbus_config
*cfg
)
708 struct adv7180_state
*state
= to_state(sd
);
710 if (state
->chip_info
->flags
& ADV7180_FLAG_MIPI_CSI2
) {
711 cfg
->type
= V4L2_MBUS_CSI2
;
712 cfg
->flags
= V4L2_MBUS_CSI2_1_LANE
|
713 V4L2_MBUS_CSI2_CHANNEL_0
|
714 V4L2_MBUS_CSI2_CONTINUOUS_CLOCK
;
717 * The ADV7180 sensor supports BT.601/656 output modes.
718 * The BT.656 is default and not yet configurable by s/w.
720 cfg
->flags
= V4L2_MBUS_MASTER
| V4L2_MBUS_PCLK_SAMPLE_RISING
|
721 V4L2_MBUS_DATA_ACTIVE_HIGH
;
722 cfg
->type
= V4L2_MBUS_BT656
;
728 static int adv7180_cropcap(struct v4l2_subdev
*sd
, struct v4l2_cropcap
*cropcap
)
730 struct adv7180_state
*state
= to_state(sd
);
732 if (state
->curr_norm
& V4L2_STD_525_60
) {
733 cropcap
->pixelaspect
.numerator
= 11;
734 cropcap
->pixelaspect
.denominator
= 10;
736 cropcap
->pixelaspect
.numerator
= 54;
737 cropcap
->pixelaspect
.denominator
= 59;
743 static int adv7180_g_tvnorms(struct v4l2_subdev
*sd
, v4l2_std_id
*norm
)
745 *norm
= V4L2_STD_ALL
;
749 static int adv7180_s_stream(struct v4l2_subdev
*sd
, int enable
)
751 struct adv7180_state
*state
= to_state(sd
);
754 /* It's always safe to stop streaming, no need to take the lock */
756 state
->streaming
= enable
;
760 /* Must wait until querystd released the lock */
761 ret
= mutex_lock_interruptible(&state
->mutex
);
764 state
->streaming
= enable
;
765 mutex_unlock(&state
->mutex
);
769 static int adv7180_subscribe_event(struct v4l2_subdev
*sd
,
771 struct v4l2_event_subscription
*sub
)
774 case V4L2_EVENT_SOURCE_CHANGE
:
775 return v4l2_src_change_event_subdev_subscribe(sd
, fh
, sub
);
776 case V4L2_EVENT_CTRL
:
777 return v4l2_ctrl_subdev_subscribe_event(sd
, fh
, sub
);
783 static const struct v4l2_subdev_video_ops adv7180_video_ops
= {
784 .s_std
= adv7180_s_std
,
785 .g_std
= adv7180_g_std
,
786 .querystd
= adv7180_querystd
,
787 .g_input_status
= adv7180_g_input_status
,
788 .s_routing
= adv7180_s_routing
,
789 .g_mbus_config
= adv7180_g_mbus_config
,
790 .cropcap
= adv7180_cropcap
,
791 .g_tvnorms
= adv7180_g_tvnorms
,
792 .s_stream
= adv7180_s_stream
,
795 static const struct v4l2_subdev_core_ops adv7180_core_ops
= {
796 .s_power
= adv7180_s_power
,
797 .subscribe_event
= adv7180_subscribe_event
,
798 .unsubscribe_event
= v4l2_event_subdev_unsubscribe
,
801 static const struct v4l2_subdev_pad_ops adv7180_pad_ops
= {
802 .enum_mbus_code
= adv7180_enum_mbus_code
,
803 .set_fmt
= adv7180_set_pad_format
,
804 .get_fmt
= adv7180_get_pad_format
,
807 static const struct v4l2_subdev_ops adv7180_ops
= {
808 .core
= &adv7180_core_ops
,
809 .video
= &adv7180_video_ops
,
810 .pad
= &adv7180_pad_ops
,
813 static irqreturn_t
adv7180_irq(int irq
, void *devid
)
815 struct adv7180_state
*state
= devid
;
818 mutex_lock(&state
->mutex
);
819 isr3
= adv7180_read(state
, ADV7180_REG_ISR3
);
821 adv7180_write(state
, ADV7180_REG_ICR3
, isr3
);
823 if (isr3
& ADV7180_IRQ3_AD_CHANGE
) {
824 static const struct v4l2_event src_ch
= {
825 .type
= V4L2_EVENT_SOURCE_CHANGE
,
826 .u
.src_change
.changes
= V4L2_EVENT_SRC_CH_RESOLUTION
,
829 v4l2_subdev_notify_event(&state
->sd
, &src_ch
);
831 mutex_unlock(&state
->mutex
);
836 static int adv7180_init(struct adv7180_state
*state
)
840 /* ITU-R BT.656-4 compatible */
841 ret
= adv7180_write(state
, ADV7180_REG_EXTENDED_OUTPUT_CONTROL
,
842 ADV7180_EXTENDED_OUTPUT_CONTROL_NTSCDIS
);
846 /* Manually set V bit end position in NTSC mode */
847 return adv7180_write(state
, ADV7180_REG_NTSC_V_BIT_END
,
848 ADV7180_NTSC_V_BIT_END_MANUAL_NVEND
);
851 static int adv7180_set_std(struct adv7180_state
*state
, unsigned int std
)
853 return adv7180_write(state
, ADV7180_REG_INPUT_CONTROL
,
854 (std
<< 4) | state
->input
);
857 static int adv7180_select_input(struct adv7180_state
*state
, unsigned int input
)
861 ret
= adv7180_read(state
, ADV7180_REG_INPUT_CONTROL
);
865 ret
&= ~ADV7180_INPUT_CONTROL_INSEL_MASK
;
867 return adv7180_write(state
, ADV7180_REG_INPUT_CONTROL
, ret
);
870 static int adv7182_init(struct adv7180_state
*state
)
872 if (state
->chip_info
->flags
& ADV7180_FLAG_MIPI_CSI2
)
873 adv7180_write(state
, ADV7180_REG_CSI_SLAVE_ADDR
,
874 ADV7180_DEFAULT_CSI_I2C_ADDR
<< 1);
876 if (state
->chip_info
->flags
& ADV7180_FLAG_I2P
)
877 adv7180_write(state
, ADV7180_REG_VPP_SLAVE_ADDR
,
878 ADV7180_DEFAULT_VPP_I2C_ADDR
<< 1);
880 if (state
->chip_info
->flags
& ADV7180_FLAG_V2
) {
881 /* ADI recommended writes for improved video quality */
882 adv7180_write(state
, 0x0080, 0x51);
883 adv7180_write(state
, 0x0081, 0x51);
884 adv7180_write(state
, 0x0082, 0x68);
887 /* ADI required writes */
888 if (state
->chip_info
->flags
& ADV7180_FLAG_MIPI_CSI2
) {
889 adv7180_write(state
, 0x0003, 0x4e);
890 adv7180_write(state
, 0x0004, 0x57);
891 adv7180_write(state
, 0x001d, 0xc0);
893 if (state
->chip_info
->flags
& ADV7180_FLAG_V2
)
894 adv7180_write(state
, 0x0004, 0x17);
896 adv7180_write(state
, 0x0004, 0x07);
897 adv7180_write(state
, 0x0003, 0x0c);
898 adv7180_write(state
, 0x001d, 0x40);
901 adv7180_write(state
, 0x0013, 0x00);
906 static int adv7182_set_std(struct adv7180_state
*state
, unsigned int std
)
908 return adv7180_write(state
, ADV7182_REG_INPUT_VIDSEL
, std
<< 4);
911 enum adv7182_input_type
{
912 ADV7182_INPUT_TYPE_CVBS
,
913 ADV7182_INPUT_TYPE_DIFF_CVBS
,
914 ADV7182_INPUT_TYPE_SVIDEO
,
915 ADV7182_INPUT_TYPE_YPBPR
,
918 static enum adv7182_input_type
adv7182_get_input_type(unsigned int input
)
921 case ADV7182_INPUT_CVBS_AIN1
:
922 case ADV7182_INPUT_CVBS_AIN2
:
923 case ADV7182_INPUT_CVBS_AIN3
:
924 case ADV7182_INPUT_CVBS_AIN4
:
925 case ADV7182_INPUT_CVBS_AIN5
:
926 case ADV7182_INPUT_CVBS_AIN6
:
927 case ADV7182_INPUT_CVBS_AIN7
:
928 case ADV7182_INPUT_CVBS_AIN8
:
929 return ADV7182_INPUT_TYPE_CVBS
;
930 case ADV7182_INPUT_SVIDEO_AIN1_AIN2
:
931 case ADV7182_INPUT_SVIDEO_AIN3_AIN4
:
932 case ADV7182_INPUT_SVIDEO_AIN5_AIN6
:
933 case ADV7182_INPUT_SVIDEO_AIN7_AIN8
:
934 return ADV7182_INPUT_TYPE_SVIDEO
;
935 case ADV7182_INPUT_YPRPB_AIN1_AIN2_AIN3
:
936 case ADV7182_INPUT_YPRPB_AIN4_AIN5_AIN6
:
937 return ADV7182_INPUT_TYPE_YPBPR
;
938 case ADV7182_INPUT_DIFF_CVBS_AIN1_AIN2
:
939 case ADV7182_INPUT_DIFF_CVBS_AIN3_AIN4
:
940 case ADV7182_INPUT_DIFF_CVBS_AIN5_AIN6
:
941 case ADV7182_INPUT_DIFF_CVBS_AIN7_AIN8
:
942 return ADV7182_INPUT_TYPE_DIFF_CVBS
;
943 default: /* Will never happen */
948 /* ADI recommended writes to registers 0x52, 0x53, 0x54 */
949 static unsigned int adv7182_lbias_settings
[][3] = {
950 [ADV7182_INPUT_TYPE_CVBS
] = { 0xCB, 0x4E, 0x80 },
951 [ADV7182_INPUT_TYPE_DIFF_CVBS
] = { 0xC0, 0x4E, 0x80 },
952 [ADV7182_INPUT_TYPE_SVIDEO
] = { 0x0B, 0xCE, 0x80 },
953 [ADV7182_INPUT_TYPE_YPBPR
] = { 0x0B, 0x4E, 0xC0 },
956 static unsigned int adv7280_lbias_settings
[][3] = {
957 [ADV7182_INPUT_TYPE_CVBS
] = { 0xCD, 0x4E, 0x80 },
958 [ADV7182_INPUT_TYPE_DIFF_CVBS
] = { 0xC0, 0x4E, 0x80 },
959 [ADV7182_INPUT_TYPE_SVIDEO
] = { 0x0B, 0xCE, 0x80 },
960 [ADV7182_INPUT_TYPE_YPBPR
] = { 0x0B, 0x4E, 0xC0 },
963 static int adv7182_select_input(struct adv7180_state
*state
, unsigned int input
)
965 enum adv7182_input_type input_type
;
970 ret
= adv7180_write(state
, ADV7180_REG_INPUT_CONTROL
, input
);
974 /* Reset clamp circuitry - ADI recommended writes */
975 adv7180_write(state
, 0x809c, 0x00);
976 adv7180_write(state
, 0x809c, 0xff);
978 input_type
= adv7182_get_input_type(input
);
980 switch (input_type
) {
981 case ADV7182_INPUT_TYPE_CVBS
:
982 case ADV7182_INPUT_TYPE_DIFF_CVBS
:
983 /* ADI recommends to use the SH1 filter */
984 adv7180_write(state
, 0x0017, 0x41);
987 adv7180_write(state
, 0x0017, 0x01);
991 if (state
->chip_info
->flags
& ADV7180_FLAG_V2
)
992 lbias
= adv7280_lbias_settings
[input_type
];
994 lbias
= adv7182_lbias_settings
[input_type
];
996 for (i
= 0; i
< ARRAY_SIZE(adv7182_lbias_settings
[0]); i
++)
997 adv7180_write(state
, 0x0052 + i
, lbias
[i
]);
999 if (input_type
== ADV7182_INPUT_TYPE_DIFF_CVBS
) {
1000 /* ADI required writes to make differential CVBS work */
1001 adv7180_write(state
, 0x005f, 0xa8);
1002 adv7180_write(state
, 0x005a, 0x90);
1003 adv7180_write(state
, 0x0060, 0xb0);
1004 adv7180_write(state
, 0x80b6, 0x08);
1005 adv7180_write(state
, 0x80c0, 0xa0);
1007 adv7180_write(state
, 0x005f, 0xf0);
1008 adv7180_write(state
, 0x005a, 0xd0);
1009 adv7180_write(state
, 0x0060, 0x10);
1010 adv7180_write(state
, 0x80b6, 0x9c);
1011 adv7180_write(state
, 0x80c0, 0x00);
1017 static const struct adv7180_chip_info adv7180_info
= {
1018 .flags
= ADV7180_FLAG_RESET_POWERED
,
1019 /* We cannot discriminate between LQFP and 40-pin LFCSP, so accept
1020 * all inputs and let the card driver take care of validation
1022 .valid_input_mask
= BIT(ADV7180_INPUT_CVBS_AIN1
) |
1023 BIT(ADV7180_INPUT_CVBS_AIN2
) |
1024 BIT(ADV7180_INPUT_CVBS_AIN3
) |
1025 BIT(ADV7180_INPUT_CVBS_AIN4
) |
1026 BIT(ADV7180_INPUT_CVBS_AIN5
) |
1027 BIT(ADV7180_INPUT_CVBS_AIN6
) |
1028 BIT(ADV7180_INPUT_SVIDEO_AIN1_AIN2
) |
1029 BIT(ADV7180_INPUT_SVIDEO_AIN3_AIN4
) |
1030 BIT(ADV7180_INPUT_SVIDEO_AIN5_AIN6
) |
1031 BIT(ADV7180_INPUT_YPRPB_AIN1_AIN2_AIN3
) |
1032 BIT(ADV7180_INPUT_YPRPB_AIN4_AIN5_AIN6
),
1033 .init
= adv7180_init
,
1034 .set_std
= adv7180_set_std
,
1035 .select_input
= adv7180_select_input
,
1038 static const struct adv7180_chip_info adv7182_info
= {
1039 .valid_input_mask
= BIT(ADV7182_INPUT_CVBS_AIN1
) |
1040 BIT(ADV7182_INPUT_CVBS_AIN2
) |
1041 BIT(ADV7182_INPUT_CVBS_AIN3
) |
1042 BIT(ADV7182_INPUT_CVBS_AIN4
) |
1043 BIT(ADV7182_INPUT_SVIDEO_AIN1_AIN2
) |
1044 BIT(ADV7182_INPUT_SVIDEO_AIN3_AIN4
) |
1045 BIT(ADV7182_INPUT_YPRPB_AIN1_AIN2_AIN3
) |
1046 BIT(ADV7182_INPUT_DIFF_CVBS_AIN1_AIN2
) |
1047 BIT(ADV7182_INPUT_DIFF_CVBS_AIN3_AIN4
),
1048 .init
= adv7182_init
,
1049 .set_std
= adv7182_set_std
,
1050 .select_input
= adv7182_select_input
,
1053 static const struct adv7180_chip_info adv7280_info
= {
1054 .flags
= ADV7180_FLAG_V2
| ADV7180_FLAG_I2P
,
1055 .valid_input_mask
= BIT(ADV7182_INPUT_CVBS_AIN1
) |
1056 BIT(ADV7182_INPUT_CVBS_AIN2
) |
1057 BIT(ADV7182_INPUT_CVBS_AIN3
) |
1058 BIT(ADV7182_INPUT_CVBS_AIN4
) |
1059 BIT(ADV7182_INPUT_SVIDEO_AIN1_AIN2
) |
1060 BIT(ADV7182_INPUT_SVIDEO_AIN3_AIN4
) |
1061 BIT(ADV7182_INPUT_YPRPB_AIN1_AIN2_AIN3
),
1062 .init
= adv7182_init
,
1063 .set_std
= adv7182_set_std
,
1064 .select_input
= adv7182_select_input
,
1067 static const struct adv7180_chip_info adv7280_m_info
= {
1068 .flags
= ADV7180_FLAG_V2
| ADV7180_FLAG_MIPI_CSI2
| ADV7180_FLAG_I2P
,
1069 .valid_input_mask
= BIT(ADV7182_INPUT_CVBS_AIN1
) |
1070 BIT(ADV7182_INPUT_CVBS_AIN2
) |
1071 BIT(ADV7182_INPUT_CVBS_AIN3
) |
1072 BIT(ADV7182_INPUT_CVBS_AIN4
) |
1073 BIT(ADV7182_INPUT_CVBS_AIN5
) |
1074 BIT(ADV7182_INPUT_CVBS_AIN6
) |
1075 BIT(ADV7182_INPUT_CVBS_AIN7
) |
1076 BIT(ADV7182_INPUT_CVBS_AIN8
) |
1077 BIT(ADV7182_INPUT_SVIDEO_AIN1_AIN2
) |
1078 BIT(ADV7182_INPUT_SVIDEO_AIN3_AIN4
) |
1079 BIT(ADV7182_INPUT_SVIDEO_AIN5_AIN6
) |
1080 BIT(ADV7182_INPUT_SVIDEO_AIN7_AIN8
) |
1081 BIT(ADV7182_INPUT_YPRPB_AIN1_AIN2_AIN3
) |
1082 BIT(ADV7182_INPUT_YPRPB_AIN4_AIN5_AIN6
),
1083 .init
= adv7182_init
,
1084 .set_std
= adv7182_set_std
,
1085 .select_input
= adv7182_select_input
,
1088 static const struct adv7180_chip_info adv7281_info
= {
1089 .flags
= ADV7180_FLAG_V2
| ADV7180_FLAG_MIPI_CSI2
,
1090 .valid_input_mask
= BIT(ADV7182_INPUT_CVBS_AIN1
) |
1091 BIT(ADV7182_INPUT_CVBS_AIN2
) |
1092 BIT(ADV7182_INPUT_CVBS_AIN7
) |
1093 BIT(ADV7182_INPUT_CVBS_AIN8
) |
1094 BIT(ADV7182_INPUT_SVIDEO_AIN1_AIN2
) |
1095 BIT(ADV7182_INPUT_SVIDEO_AIN7_AIN8
) |
1096 BIT(ADV7182_INPUT_DIFF_CVBS_AIN1_AIN2
) |
1097 BIT(ADV7182_INPUT_DIFF_CVBS_AIN7_AIN8
),
1098 .init
= adv7182_init
,
1099 .set_std
= adv7182_set_std
,
1100 .select_input
= adv7182_select_input
,
1103 static const struct adv7180_chip_info adv7281_m_info
= {
1104 .flags
= ADV7180_FLAG_V2
| ADV7180_FLAG_MIPI_CSI2
,
1105 .valid_input_mask
= BIT(ADV7182_INPUT_CVBS_AIN1
) |
1106 BIT(ADV7182_INPUT_CVBS_AIN2
) |
1107 BIT(ADV7182_INPUT_CVBS_AIN3
) |
1108 BIT(ADV7182_INPUT_CVBS_AIN4
) |
1109 BIT(ADV7182_INPUT_CVBS_AIN7
) |
1110 BIT(ADV7182_INPUT_CVBS_AIN8
) |
1111 BIT(ADV7182_INPUT_SVIDEO_AIN1_AIN2
) |
1112 BIT(ADV7182_INPUT_SVIDEO_AIN3_AIN4
) |
1113 BIT(ADV7182_INPUT_SVIDEO_AIN7_AIN8
) |
1114 BIT(ADV7182_INPUT_YPRPB_AIN1_AIN2_AIN3
) |
1115 BIT(ADV7182_INPUT_DIFF_CVBS_AIN1_AIN2
) |
1116 BIT(ADV7182_INPUT_DIFF_CVBS_AIN3_AIN4
) |
1117 BIT(ADV7182_INPUT_DIFF_CVBS_AIN7_AIN8
),
1118 .init
= adv7182_init
,
1119 .set_std
= adv7182_set_std
,
1120 .select_input
= adv7182_select_input
,
1123 static const struct adv7180_chip_info adv7281_ma_info
= {
1124 .flags
= ADV7180_FLAG_V2
| ADV7180_FLAG_MIPI_CSI2
,
1125 .valid_input_mask
= BIT(ADV7182_INPUT_CVBS_AIN1
) |
1126 BIT(ADV7182_INPUT_CVBS_AIN2
) |
1127 BIT(ADV7182_INPUT_CVBS_AIN3
) |
1128 BIT(ADV7182_INPUT_CVBS_AIN4
) |
1129 BIT(ADV7182_INPUT_CVBS_AIN5
) |
1130 BIT(ADV7182_INPUT_CVBS_AIN6
) |
1131 BIT(ADV7182_INPUT_CVBS_AIN7
) |
1132 BIT(ADV7182_INPUT_CVBS_AIN8
) |
1133 BIT(ADV7182_INPUT_SVIDEO_AIN1_AIN2
) |
1134 BIT(ADV7182_INPUT_SVIDEO_AIN3_AIN4
) |
1135 BIT(ADV7182_INPUT_SVIDEO_AIN5_AIN6
) |
1136 BIT(ADV7182_INPUT_SVIDEO_AIN7_AIN8
) |
1137 BIT(ADV7182_INPUT_YPRPB_AIN1_AIN2_AIN3
) |
1138 BIT(ADV7182_INPUT_YPRPB_AIN4_AIN5_AIN6
) |
1139 BIT(ADV7182_INPUT_DIFF_CVBS_AIN1_AIN2
) |
1140 BIT(ADV7182_INPUT_DIFF_CVBS_AIN3_AIN4
) |
1141 BIT(ADV7182_INPUT_DIFF_CVBS_AIN5_AIN6
) |
1142 BIT(ADV7182_INPUT_DIFF_CVBS_AIN7_AIN8
),
1143 .init
= adv7182_init
,
1144 .set_std
= adv7182_set_std
,
1145 .select_input
= adv7182_select_input
,
1148 static const struct adv7180_chip_info adv7282_info
= {
1149 .flags
= ADV7180_FLAG_V2
| ADV7180_FLAG_I2P
,
1150 .valid_input_mask
= BIT(ADV7182_INPUT_CVBS_AIN1
) |
1151 BIT(ADV7182_INPUT_CVBS_AIN2
) |
1152 BIT(ADV7182_INPUT_CVBS_AIN7
) |
1153 BIT(ADV7182_INPUT_CVBS_AIN8
) |
1154 BIT(ADV7182_INPUT_SVIDEO_AIN1_AIN2
) |
1155 BIT(ADV7182_INPUT_SVIDEO_AIN7_AIN8
) |
1156 BIT(ADV7182_INPUT_DIFF_CVBS_AIN1_AIN2
) |
1157 BIT(ADV7182_INPUT_DIFF_CVBS_AIN7_AIN8
),
1158 .init
= adv7182_init
,
1159 .set_std
= adv7182_set_std
,
1160 .select_input
= adv7182_select_input
,
1163 static const struct adv7180_chip_info adv7282_m_info
= {
1164 .flags
= ADV7180_FLAG_V2
| ADV7180_FLAG_MIPI_CSI2
| ADV7180_FLAG_I2P
,
1165 .valid_input_mask
= BIT(ADV7182_INPUT_CVBS_AIN1
) |
1166 BIT(ADV7182_INPUT_CVBS_AIN2
) |
1167 BIT(ADV7182_INPUT_CVBS_AIN3
) |
1168 BIT(ADV7182_INPUT_CVBS_AIN4
) |
1169 BIT(ADV7182_INPUT_CVBS_AIN7
) |
1170 BIT(ADV7182_INPUT_CVBS_AIN8
) |
1171 BIT(ADV7182_INPUT_SVIDEO_AIN1_AIN2
) |
1172 BIT(ADV7182_INPUT_SVIDEO_AIN3_AIN4
) |
1173 BIT(ADV7182_INPUT_SVIDEO_AIN7_AIN8
) |
1174 BIT(ADV7182_INPUT_DIFF_CVBS_AIN1_AIN2
) |
1175 BIT(ADV7182_INPUT_DIFF_CVBS_AIN3_AIN4
) |
1176 BIT(ADV7182_INPUT_DIFF_CVBS_AIN7_AIN8
),
1177 .init
= adv7182_init
,
1178 .set_std
= adv7182_set_std
,
1179 .select_input
= adv7182_select_input
,
1182 static int init_device(struct adv7180_state
*state
)
1186 mutex_lock(&state
->mutex
);
1188 adv7180_write(state
, ADV7180_REG_PWR_MAN
, ADV7180_PWR_MAN_RES
);
1189 usleep_range(5000, 10000);
1191 ret
= state
->chip_info
->init(state
);
1195 ret
= adv7180_program_std(state
);
1199 adv7180_set_field_mode(state
);
1201 /* register for interrupts */
1202 if (state
->irq
> 0) {
1203 /* config the Interrupt pin to be active low */
1204 ret
= adv7180_write(state
, ADV7180_REG_ICONF1
,
1205 ADV7180_ICONF1_ACTIVE_LOW
|
1206 ADV7180_ICONF1_PSYNC_ONLY
);
1210 ret
= adv7180_write(state
, ADV7180_REG_IMR1
, 0);
1214 ret
= adv7180_write(state
, ADV7180_REG_IMR2
, 0);
1218 /* enable AD change interrupts interrupts */
1219 ret
= adv7180_write(state
, ADV7180_REG_IMR3
,
1220 ADV7180_IRQ3_AD_CHANGE
);
1224 ret
= adv7180_write(state
, ADV7180_REG_IMR4
, 0);
1230 mutex_unlock(&state
->mutex
);
1235 static int adv7180_probe(struct i2c_client
*client
,
1236 const struct i2c_device_id
*id
)
1238 struct adv7180_state
*state
;
1239 struct v4l2_subdev
*sd
;
1242 /* Check if the adapter supports the needed features */
1243 if (!i2c_check_functionality(client
->adapter
, I2C_FUNC_SMBUS_BYTE_DATA
))
1246 v4l_info(client
, "chip found @ 0x%02x (%s)\n",
1247 client
->addr
, client
->adapter
->name
);
1249 state
= devm_kzalloc(&client
->dev
, sizeof(*state
), GFP_KERNEL
);
1253 state
->client
= client
;
1254 state
->field
= V4L2_FIELD_INTERLACED
;
1255 state
->chip_info
= (struct adv7180_chip_info
*)id
->driver_data
;
1257 if (state
->chip_info
->flags
& ADV7180_FLAG_MIPI_CSI2
) {
1258 state
->csi_client
= i2c_new_dummy(client
->adapter
,
1259 ADV7180_DEFAULT_CSI_I2C_ADDR
);
1260 if (!state
->csi_client
)
1264 if (state
->chip_info
->flags
& ADV7180_FLAG_I2P
) {
1265 state
->vpp_client
= i2c_new_dummy(client
->adapter
,
1266 ADV7180_DEFAULT_VPP_I2C_ADDR
);
1267 if (!state
->vpp_client
) {
1269 goto err_unregister_csi_client
;
1273 state
->irq
= client
->irq
;
1274 mutex_init(&state
->mutex
);
1275 state
->curr_norm
= V4L2_STD_NTSC
;
1276 if (state
->chip_info
->flags
& ADV7180_FLAG_RESET_POWERED
)
1277 state
->powered
= true;
1279 state
->powered
= false;
1282 v4l2_i2c_subdev_init(sd
, client
, &adv7180_ops
);
1283 sd
->flags
= V4L2_SUBDEV_FL_HAS_DEVNODE
| V4L2_SUBDEV_FL_HAS_EVENTS
;
1285 ret
= adv7180_init_controls(state
);
1287 goto err_unregister_vpp_client
;
1289 state
->pad
.flags
= MEDIA_PAD_FL_SOURCE
;
1290 sd
->entity
.flags
|= MEDIA_ENT_F_ATV_DECODER
;
1291 ret
= media_entity_pads_init(&sd
->entity
, 1, &state
->pad
);
1295 ret
= init_device(state
);
1297 goto err_media_entity_cleanup
;
1300 ret
= request_threaded_irq(client
->irq
, NULL
, adv7180_irq
,
1301 IRQF_ONESHOT
| IRQF_TRIGGER_FALLING
,
1302 KBUILD_MODNAME
, state
);
1304 goto err_media_entity_cleanup
;
1307 ret
= v4l2_async_register_subdev(sd
);
1315 free_irq(client
->irq
, state
);
1316 err_media_entity_cleanup
:
1317 media_entity_cleanup(&sd
->entity
);
1319 adv7180_exit_controls(state
);
1320 err_unregister_vpp_client
:
1321 if (state
->chip_info
->flags
& ADV7180_FLAG_I2P
)
1322 i2c_unregister_device(state
->vpp_client
);
1323 err_unregister_csi_client
:
1324 if (state
->chip_info
->flags
& ADV7180_FLAG_MIPI_CSI2
)
1325 i2c_unregister_device(state
->csi_client
);
1326 mutex_destroy(&state
->mutex
);
1330 static int adv7180_remove(struct i2c_client
*client
)
1332 struct v4l2_subdev
*sd
= i2c_get_clientdata(client
);
1333 struct adv7180_state
*state
= to_state(sd
);
1335 v4l2_async_unregister_subdev(sd
);
1338 free_irq(client
->irq
, state
);
1340 media_entity_cleanup(&sd
->entity
);
1341 adv7180_exit_controls(state
);
1343 if (state
->chip_info
->flags
& ADV7180_FLAG_I2P
)
1344 i2c_unregister_device(state
->vpp_client
);
1345 if (state
->chip_info
->flags
& ADV7180_FLAG_MIPI_CSI2
)
1346 i2c_unregister_device(state
->csi_client
);
1348 mutex_destroy(&state
->mutex
);
1353 static const struct i2c_device_id adv7180_id
[] = {
1354 { "adv7180", (kernel_ulong_t
)&adv7180_info
},
1355 { "adv7182", (kernel_ulong_t
)&adv7182_info
},
1356 { "adv7280", (kernel_ulong_t
)&adv7280_info
},
1357 { "adv7280-m", (kernel_ulong_t
)&adv7280_m_info
},
1358 { "adv7281", (kernel_ulong_t
)&adv7281_info
},
1359 { "adv7281-m", (kernel_ulong_t
)&adv7281_m_info
},
1360 { "adv7281-ma", (kernel_ulong_t
)&adv7281_ma_info
},
1361 { "adv7282", (kernel_ulong_t
)&adv7282_info
},
1362 { "adv7282-m", (kernel_ulong_t
)&adv7282_m_info
},
1365 MODULE_DEVICE_TABLE(i2c
, adv7180_id
);
1367 #ifdef CONFIG_PM_SLEEP
1368 static int adv7180_suspend(struct device
*dev
)
1370 struct i2c_client
*client
= to_i2c_client(dev
);
1371 struct v4l2_subdev
*sd
= i2c_get_clientdata(client
);
1372 struct adv7180_state
*state
= to_state(sd
);
1374 return adv7180_set_power(state
, false);
1377 static int adv7180_resume(struct device
*dev
)
1379 struct i2c_client
*client
= to_i2c_client(dev
);
1380 struct v4l2_subdev
*sd
= i2c_get_clientdata(client
);
1381 struct adv7180_state
*state
= to_state(sd
);
1384 ret
= init_device(state
);
1388 ret
= adv7180_set_power(state
, state
->powered
);
1395 static SIMPLE_DEV_PM_OPS(adv7180_pm_ops
, adv7180_suspend
, adv7180_resume
);
1396 #define ADV7180_PM_OPS (&adv7180_pm_ops)
1399 #define ADV7180_PM_OPS NULL
1403 static const struct of_device_id adv7180_of_id
[] = {
1404 { .compatible
= "adi,adv7180", },
1405 { .compatible
= "adi,adv7182", },
1406 { .compatible
= "adi,adv7280", },
1407 { .compatible
= "adi,adv7280-m", },
1408 { .compatible
= "adi,adv7281", },
1409 { .compatible
= "adi,adv7281-m", },
1410 { .compatible
= "adi,adv7281-ma", },
1411 { .compatible
= "adi,adv7282", },
1412 { .compatible
= "adi,adv7282-m", },
1416 MODULE_DEVICE_TABLE(of
, adv7180_of_id
);
1419 static struct i2c_driver adv7180_driver
= {
1421 .name
= KBUILD_MODNAME
,
1422 .pm
= ADV7180_PM_OPS
,
1423 .of_match_table
= of_match_ptr(adv7180_of_id
),
1425 .probe
= adv7180_probe
,
1426 .remove
= adv7180_remove
,
1427 .id_table
= adv7180_id
,
1430 module_i2c_driver(adv7180_driver
);
1432 MODULE_DESCRIPTION("Analog Devices ADV7180 video decoder driver");
1433 MODULE_AUTHOR("Mocean Laboratories");
1434 MODULE_LICENSE("GPL v2");