Kuninori Morimoto | 661521a | 2018-08-05 23:17:30 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Richard Röjfors | 6789cb5 | 2009-09-18 21:17:20 -0300 | [diff] [blame] | 2 | /* |
| 3 | * adv7180.c Analog Devices ADV7180 video decoder driver |
| 4 | * Copyright (c) 2009 Intel Corporation |
Vladimir Barinov | cccb83f | 2013-05-29 14:50:57 -0300 | [diff] [blame] | 5 | * Copyright (C) 2013 Cogent Embedded, Inc. |
| 6 | * Copyright (C) 2013 Renesas Solutions Corp. |
Richard Röjfors | 6789cb5 | 2009-09-18 21:17:20 -0300 | [diff] [blame] | 7 | */ |
Richard Röjfors | 6789cb5 | 2009-09-18 21:17:20 -0300 | [diff] [blame] | 8 | #include <linux/module.h> |
| 9 | #include <linux/init.h> |
| 10 | #include <linux/errno.h> |
| 11 | #include <linux/kernel.h> |
| 12 | #include <linux/interrupt.h> |
| 13 | #include <linux/i2c.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 14 | #include <linux/slab.h> |
Ben Dooks | 250121d | 2015-06-03 10:59:50 -0300 | [diff] [blame] | 15 | #include <linux/of.h> |
Steve Longerbeam | 65d9e14 | 2016-07-19 21:03:32 -0300 | [diff] [blame] | 16 | #include <linux/gpio/consumer.h> |
Richard Röjfors | 6789cb5 | 2009-09-18 21:17:20 -0300 | [diff] [blame] | 17 | #include <linux/videodev2.h> |
Hans Verkuil | 937feee | 2016-04-22 10:03:37 -0300 | [diff] [blame] | 18 | #include <media/v4l2-ioctl.h> |
| 19 | #include <media/v4l2-event.h> |
Richard Röjfors | 6789cb5 | 2009-09-18 21:17:20 -0300 | [diff] [blame] | 20 | #include <media/v4l2-device.h> |
Federico Vaga | c9fbedd | 2012-07-11 11:29:33 -0300 | [diff] [blame] | 21 | #include <media/v4l2-ctrls.h> |
Richard Röjfors | 42752f7 | 2009-09-22 06:07:06 -0300 | [diff] [blame] | 22 | #include <linux/mutex.h> |
Lars-Peter Clausen | c18818e | 2015-01-23 12:52:25 -0300 | [diff] [blame] | 23 | #include <linux/delay.h> |
Richard Röjfors | 6789cb5 | 2009-09-18 21:17:20 -0300 | [diff] [blame] | 24 | |
Lars-Peter Clausen | f5dde49 | 2015-01-23 12:52:28 -0300 | [diff] [blame] | 25 | #define ADV7180_STD_AD_PAL_BG_NTSC_J_SECAM 0x0 |
| 26 | #define ADV7180_STD_AD_PAL_BG_NTSC_J_SECAM_PED 0x1 |
| 27 | #define ADV7180_STD_AD_PAL_N_NTSC_J_SECAM 0x2 |
| 28 | #define ADV7180_STD_AD_PAL_N_NTSC_M_SECAM 0x3 |
| 29 | #define ADV7180_STD_NTSC_J 0x4 |
| 30 | #define ADV7180_STD_NTSC_M 0x5 |
| 31 | #define ADV7180_STD_PAL60 0x6 |
| 32 | #define ADV7180_STD_NTSC_443 0x7 |
| 33 | #define ADV7180_STD_PAL_BG 0x8 |
| 34 | #define ADV7180_STD_PAL_N 0x9 |
| 35 | #define ADV7180_STD_PAL_M 0xa |
| 36 | #define ADV7180_STD_PAL_M_PED 0xb |
| 37 | #define ADV7180_STD_PAL_COMB_N 0xc |
| 38 | #define ADV7180_STD_PAL_COMB_N_PED 0xd |
| 39 | #define ADV7180_STD_PAL_SECAM 0xe |
| 40 | #define ADV7180_STD_PAL_SECAM_PED 0xf |
| 41 | |
Lars-Peter Clausen | 3999e5d | 2015-01-23 12:52:24 -0300 | [diff] [blame] | 42 | #define ADV7180_REG_INPUT_CONTROL 0x0000 |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 43 | #define ADV7180_INPUT_CONTROL_INSEL_MASK 0x0f |
Richard Röjfors | d312429 | 2009-09-22 06:05:42 -0300 | [diff] [blame] | 44 | |
Lars-Peter Clausen | c5ef8f8 | 2015-01-23 12:52:29 -0300 | [diff] [blame] | 45 | #define ADV7182_REG_INPUT_VIDSEL 0x0002 |
| 46 | |
Steve Longerbeam | ce5d629 | 2016-07-19 21:03:30 -0300 | [diff] [blame] | 47 | #define ADV7180_REG_OUTPUT_CONTROL 0x0003 |
Lars-Peter Clausen | 3999e5d | 2015-01-23 12:52:24 -0300 | [diff] [blame] | 48 | #define ADV7180_REG_EXTENDED_OUTPUT_CONTROL 0x0004 |
Richard Röjfors | 42752f7 | 2009-09-22 06:07:06 -0300 | [diff] [blame] | 49 | #define ADV7180_EXTENDED_OUTPUT_CONTROL_NTSCDIS 0xC5 |
Richard Röjfors | 6789cb5 | 2009-09-18 21:17:20 -0300 | [diff] [blame] | 50 | |
Steve Longerbeam | ce5d629 | 2016-07-19 21:03:30 -0300 | [diff] [blame] | 51 | #define ADV7180_REG_AUTODETECT_ENABLE 0x0007 |
Richard Röjfors | 42752f7 | 2009-09-22 06:07:06 -0300 | [diff] [blame] | 52 | #define ADV7180_AUTODETECT_DEFAULT 0x7f |
Federico Vaga | c9fbedd | 2012-07-11 11:29:33 -0300 | [diff] [blame] | 53 | /* Contrast */ |
Lars-Peter Clausen | 3999e5d | 2015-01-23 12:52:24 -0300 | [diff] [blame] | 54 | #define ADV7180_REG_CON 0x0008 /*Unsigned */ |
Federico Vaga | c9fbedd | 2012-07-11 11:29:33 -0300 | [diff] [blame] | 55 | #define ADV7180_CON_MIN 0 |
| 56 | #define ADV7180_CON_DEF 128 |
| 57 | #define ADV7180_CON_MAX 255 |
| 58 | /* Brightness*/ |
Lars-Peter Clausen | 3999e5d | 2015-01-23 12:52:24 -0300 | [diff] [blame] | 59 | #define ADV7180_REG_BRI 0x000a /*Signed */ |
Federico Vaga | c9fbedd | 2012-07-11 11:29:33 -0300 | [diff] [blame] | 60 | #define ADV7180_BRI_MIN -128 |
| 61 | #define ADV7180_BRI_DEF 0 |
| 62 | #define ADV7180_BRI_MAX 127 |
| 63 | /* Hue */ |
Lars-Peter Clausen | 3999e5d | 2015-01-23 12:52:24 -0300 | [diff] [blame] | 64 | #define ADV7180_REG_HUE 0x000b /*Signed, inverted */ |
Federico Vaga | c9fbedd | 2012-07-11 11:29:33 -0300 | [diff] [blame] | 65 | #define ADV7180_HUE_MIN -127 |
| 66 | #define ADV7180_HUE_DEF 0 |
| 67 | #define ADV7180_HUE_MAX 128 |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 68 | |
Lars-Peter Clausen | 3999e5d | 2015-01-23 12:52:24 -0300 | [diff] [blame] | 69 | #define ADV7180_REG_CTRL 0x000e |
Lars-Peter Clausen | 029d617 | 2015-01-23 12:52:23 -0300 | [diff] [blame] | 70 | #define ADV7180_CTRL_IRQ_SPACE 0x20 |
Richard Röjfors | 6789cb5 | 2009-09-18 21:17:20 -0300 | [diff] [blame] | 71 | |
Lars-Peter Clausen | 029d617 | 2015-01-23 12:52:23 -0300 | [diff] [blame] | 72 | #define ADV7180_REG_PWR_MAN 0x0f |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 73 | #define ADV7180_PWR_MAN_ON 0x04 |
| 74 | #define ADV7180_PWR_MAN_OFF 0x24 |
| 75 | #define ADV7180_PWR_MAN_RES 0x80 |
| 76 | |
Lars-Peter Clausen | 3999e5d | 2015-01-23 12:52:24 -0300 | [diff] [blame] | 77 | #define ADV7180_REG_STATUS1 0x0010 |
Richard Röjfors | d312429 | 2009-09-22 06:05:42 -0300 | [diff] [blame] | 78 | #define ADV7180_STATUS1_IN_LOCK 0x01 |
| 79 | #define ADV7180_STATUS1_AUTOD_MASK 0x70 |
Richard Röjfors | 6789cb5 | 2009-09-18 21:17:20 -0300 | [diff] [blame] | 80 | #define ADV7180_STATUS1_AUTOD_NTSM_M_J 0x00 |
| 81 | #define ADV7180_STATUS1_AUTOD_NTSC_4_43 0x10 |
| 82 | #define ADV7180_STATUS1_AUTOD_PAL_M 0x20 |
| 83 | #define ADV7180_STATUS1_AUTOD_PAL_60 0x30 |
| 84 | #define ADV7180_STATUS1_AUTOD_PAL_B_G 0x40 |
| 85 | #define ADV7180_STATUS1_AUTOD_SECAM 0x50 |
| 86 | #define ADV7180_STATUS1_AUTOD_PAL_COMB 0x60 |
| 87 | #define ADV7180_STATUS1_AUTOD_SECAM_525 0x70 |
| 88 | |
Lars-Peter Clausen | 3999e5d | 2015-01-23 12:52:24 -0300 | [diff] [blame] | 89 | #define ADV7180_REG_IDENT 0x0011 |
Richard Röjfors | 6789cb5 | 2009-09-18 21:17:20 -0300 | [diff] [blame] | 90 | #define ADV7180_ID_7180 0x18 |
| 91 | |
Steve Longerbeam | ce5d629 | 2016-07-19 21:03:30 -0300 | [diff] [blame] | 92 | #define ADV7180_REG_STATUS3 0x0013 |
| 93 | #define ADV7180_REG_ANALOG_CLAMP_CTL 0x0014 |
| 94 | #define ADV7180_REG_SHAP_FILTER_CTL_1 0x0017 |
| 95 | #define ADV7180_REG_CTRL_2 0x001d |
| 96 | #define ADV7180_REG_VSYNC_FIELD_CTL_1 0x0031 |
| 97 | #define ADV7180_REG_MANUAL_WIN_CTL_1 0x003d |
| 98 | #define ADV7180_REG_MANUAL_WIN_CTL_2 0x003e |
| 99 | #define ADV7180_REG_MANUAL_WIN_CTL_3 0x003f |
| 100 | #define ADV7180_REG_LOCK_CNT 0x0051 |
| 101 | #define ADV7180_REG_CVBS_TRIM 0x0052 |
| 102 | #define ADV7180_REG_CLAMP_ADJ 0x005a |
| 103 | #define ADV7180_REG_RES_CIR 0x005f |
| 104 | #define ADV7180_REG_DIFF_MODE 0x0060 |
| 105 | |
Steve Longerbeam | 52e37f0 | 2016-07-19 21:03:29 -0300 | [diff] [blame] | 106 | #define ADV7180_REG_ICONF1 0x2040 |
Richard Röjfors | 42752f7 | 2009-09-22 06:07:06 -0300 | [diff] [blame] | 107 | #define ADV7180_ICONF1_ACTIVE_LOW 0x01 |
| 108 | #define ADV7180_ICONF1_PSYNC_ONLY 0x10 |
| 109 | #define ADV7180_ICONF1_ACTIVE_TO_CLR 0xC0 |
Federico Vaga | c9fbedd | 2012-07-11 11:29:33 -0300 | [diff] [blame] | 110 | /* Saturation */ |
Lars-Peter Clausen | 3999e5d | 2015-01-23 12:52:24 -0300 | [diff] [blame] | 111 | #define ADV7180_REG_SD_SAT_CB 0x00e3 /*Unsigned */ |
| 112 | #define ADV7180_REG_SD_SAT_CR 0x00e4 /*Unsigned */ |
Federico Vaga | c9fbedd | 2012-07-11 11:29:33 -0300 | [diff] [blame] | 113 | #define ADV7180_SAT_MIN 0 |
| 114 | #define ADV7180_SAT_DEF 128 |
| 115 | #define ADV7180_SAT_MAX 255 |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 116 | |
Richard Röjfors | 42752f7 | 2009-09-22 06:07:06 -0300 | [diff] [blame] | 117 | #define ADV7180_IRQ1_LOCK 0x01 |
| 118 | #define ADV7180_IRQ1_UNLOCK 0x02 |
Steve Longerbeam | 52e37f0 | 2016-07-19 21:03:29 -0300 | [diff] [blame] | 119 | #define ADV7180_REG_ISR1 0x2042 |
| 120 | #define ADV7180_REG_ICR1 0x2043 |
| 121 | #define ADV7180_REG_IMR1 0x2044 |
| 122 | #define ADV7180_REG_IMR2 0x2048 |
Richard Röjfors | 42752f7 | 2009-09-22 06:07:06 -0300 | [diff] [blame] | 123 | #define ADV7180_IRQ3_AD_CHANGE 0x08 |
Steve Longerbeam | 52e37f0 | 2016-07-19 21:03:29 -0300 | [diff] [blame] | 124 | #define ADV7180_REG_ISR3 0x204A |
| 125 | #define ADV7180_REG_ICR3 0x204B |
| 126 | #define ADV7180_REG_IMR3 0x204C |
| 127 | #define ADV7180_REG_IMR4 0x2050 |
Richard Röjfors | 6789cb5 | 2009-09-18 21:17:20 -0300 | [diff] [blame] | 128 | |
Lars-Peter Clausen | 3999e5d | 2015-01-23 12:52:24 -0300 | [diff] [blame] | 129 | #define ADV7180_REG_NTSC_V_BIT_END 0x00E6 |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 130 | #define ADV7180_NTSC_V_BIT_END_MANUAL_NVEND 0x4F |
| 131 | |
Lars-Peter Clausen | 851a54e | 2015-01-23 12:52:32 -0300 | [diff] [blame] | 132 | #define ADV7180_REG_VPP_SLAVE_ADDR 0xFD |
Lars-Peter Clausen | b37135e | 2015-01-23 12:52:31 -0300 | [diff] [blame] | 133 | #define ADV7180_REG_CSI_SLAVE_ADDR 0xFE |
| 134 | |
Steve Longerbeam | ce5d629 | 2016-07-19 21:03:30 -0300 | [diff] [blame] | 135 | #define ADV7180_REG_ACE_CTRL1 0x4080 |
| 136 | #define ADV7180_REG_ACE_CTRL5 0x4084 |
| 137 | #define ADV7180_REG_FLCONTROL 0x40e0 |
Lars-Peter Clausen | 08b717c | 2015-01-23 12:52:33 -0300 | [diff] [blame] | 138 | #define ADV7180_FLCONTROL_FL_ENABLE 0x1 |
| 139 | |
Steve Longerbeam | ce5d629 | 2016-07-19 21:03:30 -0300 | [diff] [blame] | 140 | #define ADV7180_REG_RST_CLAMP 0x809c |
| 141 | #define ADV7180_REG_AGC_ADJ1 0x80b6 |
| 142 | #define ADV7180_REG_AGC_ADJ2 0x80c0 |
| 143 | |
Lars-Peter Clausen | b37135e | 2015-01-23 12:52:31 -0300 | [diff] [blame] | 144 | #define ADV7180_CSI_REG_PWRDN 0x00 |
| 145 | #define ADV7180_CSI_PWRDN 0x80 |
| 146 | |
Lars-Peter Clausen | f5dde49 | 2015-01-23 12:52:28 -0300 | [diff] [blame] | 147 | #define ADV7180_INPUT_CVBS_AIN1 0x00 |
| 148 | #define ADV7180_INPUT_CVBS_AIN2 0x01 |
| 149 | #define ADV7180_INPUT_CVBS_AIN3 0x02 |
| 150 | #define ADV7180_INPUT_CVBS_AIN4 0x03 |
| 151 | #define ADV7180_INPUT_CVBS_AIN5 0x04 |
| 152 | #define ADV7180_INPUT_CVBS_AIN6 0x05 |
| 153 | #define ADV7180_INPUT_SVIDEO_AIN1_AIN2 0x06 |
| 154 | #define ADV7180_INPUT_SVIDEO_AIN3_AIN4 0x07 |
| 155 | #define ADV7180_INPUT_SVIDEO_AIN5_AIN6 0x08 |
| 156 | #define ADV7180_INPUT_YPRPB_AIN1_AIN2_AIN3 0x09 |
| 157 | #define ADV7180_INPUT_YPRPB_AIN4_AIN5_AIN6 0x0a |
| 158 | |
Lars-Peter Clausen | c5ef8f8 | 2015-01-23 12:52:29 -0300 | [diff] [blame] | 159 | #define ADV7182_INPUT_CVBS_AIN1 0x00 |
| 160 | #define ADV7182_INPUT_CVBS_AIN2 0x01 |
| 161 | #define ADV7182_INPUT_CVBS_AIN3 0x02 |
| 162 | #define ADV7182_INPUT_CVBS_AIN4 0x03 |
| 163 | #define ADV7182_INPUT_CVBS_AIN5 0x04 |
| 164 | #define ADV7182_INPUT_CVBS_AIN6 0x05 |
| 165 | #define ADV7182_INPUT_CVBS_AIN7 0x06 |
| 166 | #define ADV7182_INPUT_CVBS_AIN8 0x07 |
| 167 | #define ADV7182_INPUT_SVIDEO_AIN1_AIN2 0x08 |
| 168 | #define ADV7182_INPUT_SVIDEO_AIN3_AIN4 0x09 |
| 169 | #define ADV7182_INPUT_SVIDEO_AIN5_AIN6 0x0a |
| 170 | #define ADV7182_INPUT_SVIDEO_AIN7_AIN8 0x0b |
| 171 | #define ADV7182_INPUT_YPRPB_AIN1_AIN2_AIN3 0x0c |
| 172 | #define ADV7182_INPUT_YPRPB_AIN4_AIN5_AIN6 0x0d |
| 173 | #define ADV7182_INPUT_DIFF_CVBS_AIN1_AIN2 0x0e |
| 174 | #define ADV7182_INPUT_DIFF_CVBS_AIN3_AIN4 0x0f |
| 175 | #define ADV7182_INPUT_DIFF_CVBS_AIN5_AIN6 0x10 |
| 176 | #define ADV7182_INPUT_DIFF_CVBS_AIN7_AIN8 0x11 |
| 177 | |
Lars-Peter Clausen | b37135e | 2015-01-23 12:52:31 -0300 | [diff] [blame] | 178 | #define ADV7180_DEFAULT_CSI_I2C_ADDR 0x44 |
Lars-Peter Clausen | 851a54e | 2015-01-23 12:52:32 -0300 | [diff] [blame] | 179 | #define ADV7180_DEFAULT_VPP_I2C_ADDR 0x42 |
Lars-Peter Clausen | b37135e | 2015-01-23 12:52:31 -0300 | [diff] [blame] | 180 | |
Lars-Peter Clausen | 08b717c | 2015-01-23 12:52:33 -0300 | [diff] [blame] | 181 | #define V4L2_CID_ADV_FAST_SWITCH (V4L2_CID_USER_ADV7180_BASE + 0x00) |
| 182 | |
Tim Harvey | 9483a3f | 2018-10-24 16:25:51 -0400 | [diff] [blame] | 183 | /* Initial number of frames to skip to avoid possible garbage */ |
| 184 | #define ADV7180_NUM_OF_SKIP_FRAMES 2 |
| 185 | |
Lars-Peter Clausen | f5dde49 | 2015-01-23 12:52:28 -0300 | [diff] [blame] | 186 | struct adv7180_state; |
| 187 | |
| 188 | #define ADV7180_FLAG_RESET_POWERED BIT(0) |
Lars-Peter Clausen | bf7dcb8 | 2015-01-23 12:52:30 -0300 | [diff] [blame] | 189 | #define ADV7180_FLAG_V2 BIT(1) |
Lars-Peter Clausen | b37135e | 2015-01-23 12:52:31 -0300 | [diff] [blame] | 190 | #define ADV7180_FLAG_MIPI_CSI2 BIT(2) |
Lars-Peter Clausen | 851a54e | 2015-01-23 12:52:32 -0300 | [diff] [blame] | 191 | #define ADV7180_FLAG_I2P BIT(3) |
Lars-Peter Clausen | f5dde49 | 2015-01-23 12:52:28 -0300 | [diff] [blame] | 192 | |
| 193 | struct adv7180_chip_info { |
| 194 | unsigned int flags; |
| 195 | unsigned int valid_input_mask; |
| 196 | int (*set_std)(struct adv7180_state *st, unsigned int std); |
| 197 | int (*select_input)(struct adv7180_state *st, unsigned int input); |
| 198 | int (*init)(struct adv7180_state *state); |
| 199 | }; |
| 200 | |
Richard Röjfors | 6789cb5 | 2009-09-18 21:17:20 -0300 | [diff] [blame] | 201 | struct adv7180_state { |
Federico Vaga | c9fbedd | 2012-07-11 11:29:33 -0300 | [diff] [blame] | 202 | struct v4l2_ctrl_handler ctrl_hdl; |
Richard Röjfors | c277b60 | 2009-09-22 06:06:34 -0300 | [diff] [blame] | 203 | struct v4l2_subdev sd; |
Lars-Peter Clausen | d5d51a8 | 2015-01-23 12:52:26 -0300 | [diff] [blame] | 204 | struct media_pad pad; |
Richard Röjfors | 42752f7 | 2009-09-22 06:07:06 -0300 | [diff] [blame] | 205 | struct mutex mutex; /* mutual excl. when accessing chip */ |
| 206 | int irq; |
Steve Longerbeam | 65d9e14 | 2016-07-19 21:03:32 -0300 | [diff] [blame] | 207 | struct gpio_desc *pwdn_gpio; |
Richard Röjfors | c277b60 | 2009-09-22 06:06:34 -0300 | [diff] [blame] | 208 | v4l2_std_id curr_norm; |
Lars-Peter Clausen | e246c33 | 2014-03-10 14:05:39 -0300 | [diff] [blame] | 209 | bool powered; |
Hans Verkuil | 937feee | 2016-04-22 10:03:37 -0300 | [diff] [blame] | 210 | bool streaming; |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 211 | u8 input; |
Lars-Peter Clausen | 3999e5d | 2015-01-23 12:52:24 -0300 | [diff] [blame] | 212 | |
| 213 | struct i2c_client *client; |
| 214 | unsigned int register_page; |
Lars-Peter Clausen | b37135e | 2015-01-23 12:52:31 -0300 | [diff] [blame] | 215 | struct i2c_client *csi_client; |
Lars-Peter Clausen | 851a54e | 2015-01-23 12:52:32 -0300 | [diff] [blame] | 216 | struct i2c_client *vpp_client; |
Lars-Peter Clausen | f5dde49 | 2015-01-23 12:52:28 -0300 | [diff] [blame] | 217 | const struct adv7180_chip_info *chip_info; |
Lars-Peter Clausen | 851a54e | 2015-01-23 12:52:32 -0300 | [diff] [blame] | 218 | enum v4l2_field field; |
Richard Röjfors | 6789cb5 | 2009-09-18 21:17:20 -0300 | [diff] [blame] | 219 | }; |
Federico Vaga | c9fbedd | 2012-07-11 11:29:33 -0300 | [diff] [blame] | 220 | #define to_adv7180_sd(_ctrl) (&container_of(_ctrl->handler, \ |
| 221 | struct adv7180_state, \ |
| 222 | ctrl_hdl)->sd) |
Richard Röjfors | 6789cb5 | 2009-09-18 21:17:20 -0300 | [diff] [blame] | 223 | |
Lars-Peter Clausen | 3999e5d | 2015-01-23 12:52:24 -0300 | [diff] [blame] | 224 | static int adv7180_select_page(struct adv7180_state *state, unsigned int page) |
| 225 | { |
| 226 | if (state->register_page != page) { |
| 227 | i2c_smbus_write_byte_data(state->client, ADV7180_REG_CTRL, |
| 228 | page); |
| 229 | state->register_page = page; |
| 230 | } |
| 231 | |
| 232 | return 0; |
| 233 | } |
| 234 | |
| 235 | static int adv7180_write(struct adv7180_state *state, unsigned int reg, |
| 236 | unsigned int value) |
| 237 | { |
| 238 | lockdep_assert_held(&state->mutex); |
| 239 | adv7180_select_page(state, reg >> 8); |
| 240 | return i2c_smbus_write_byte_data(state->client, reg & 0xff, value); |
| 241 | } |
| 242 | |
| 243 | static int adv7180_read(struct adv7180_state *state, unsigned int reg) |
| 244 | { |
| 245 | lockdep_assert_held(&state->mutex); |
| 246 | adv7180_select_page(state, reg >> 8); |
| 247 | return i2c_smbus_read_byte_data(state->client, reg & 0xff); |
| 248 | } |
| 249 | |
Lars-Peter Clausen | b37135e | 2015-01-23 12:52:31 -0300 | [diff] [blame] | 250 | static int adv7180_csi_write(struct adv7180_state *state, unsigned int reg, |
| 251 | unsigned int value) |
| 252 | { |
| 253 | return i2c_smbus_write_byte_data(state->csi_client, reg, value); |
| 254 | } |
| 255 | |
Lars-Peter Clausen | f5dde49 | 2015-01-23 12:52:28 -0300 | [diff] [blame] | 256 | static int adv7180_set_video_standard(struct adv7180_state *state, |
| 257 | unsigned int std) |
| 258 | { |
| 259 | return state->chip_info->set_std(state, std); |
| 260 | } |
Lars-Peter Clausen | 3999e5d | 2015-01-23 12:52:24 -0300 | [diff] [blame] | 261 | |
Lars-Peter Clausen | 851a54e | 2015-01-23 12:52:32 -0300 | [diff] [blame] | 262 | static int adv7180_vpp_write(struct adv7180_state *state, unsigned int reg, |
| 263 | unsigned int value) |
| 264 | { |
| 265 | return i2c_smbus_write_byte_data(state->vpp_client, reg, value); |
| 266 | } |
| 267 | |
Richard Röjfors | d312429 | 2009-09-22 06:05:42 -0300 | [diff] [blame] | 268 | static v4l2_std_id adv7180_std_to_v4l2(u8 status1) |
Richard Röjfors | 6789cb5 | 2009-09-18 21:17:20 -0300 | [diff] [blame] | 269 | { |
Vladimir Barinov | b294a19 | 2013-04-11 18:06:46 -0300 | [diff] [blame] | 270 | /* in case V4L2_IN_ST_NO_SIGNAL */ |
| 271 | if (!(status1 & ADV7180_STATUS1_IN_LOCK)) |
| 272 | return V4L2_STD_UNKNOWN; |
| 273 | |
Richard Röjfors | 6789cb5 | 2009-09-18 21:17:20 -0300 | [diff] [blame] | 274 | switch (status1 & ADV7180_STATUS1_AUTOD_MASK) { |
| 275 | case ADV7180_STATUS1_AUTOD_NTSM_M_J: |
Richard Röjfors | d312429 | 2009-09-22 06:05:42 -0300 | [diff] [blame] | 276 | return V4L2_STD_NTSC; |
Richard Röjfors | 6789cb5 | 2009-09-18 21:17:20 -0300 | [diff] [blame] | 277 | case ADV7180_STATUS1_AUTOD_NTSC_4_43: |
| 278 | return V4L2_STD_NTSC_443; |
| 279 | case ADV7180_STATUS1_AUTOD_PAL_M: |
| 280 | return V4L2_STD_PAL_M; |
| 281 | case ADV7180_STATUS1_AUTOD_PAL_60: |
| 282 | return V4L2_STD_PAL_60; |
| 283 | case ADV7180_STATUS1_AUTOD_PAL_B_G: |
| 284 | return V4L2_STD_PAL; |
| 285 | case ADV7180_STATUS1_AUTOD_SECAM: |
| 286 | return V4L2_STD_SECAM; |
| 287 | case ADV7180_STATUS1_AUTOD_PAL_COMB: |
| 288 | return V4L2_STD_PAL_Nc | V4L2_STD_PAL_N; |
| 289 | case ADV7180_STATUS1_AUTOD_SECAM_525: |
| 290 | return V4L2_STD_SECAM; |
| 291 | default: |
| 292 | return V4L2_STD_UNKNOWN; |
| 293 | } |
| 294 | } |
| 295 | |
Richard Röjfors | c277b60 | 2009-09-22 06:06:34 -0300 | [diff] [blame] | 296 | static int v4l2_std_to_adv7180(v4l2_std_id std) |
| 297 | { |
| 298 | if (std == V4L2_STD_PAL_60) |
Lars-Peter Clausen | f5dde49 | 2015-01-23 12:52:28 -0300 | [diff] [blame] | 299 | return ADV7180_STD_PAL60; |
Richard Röjfors | c277b60 | 2009-09-22 06:06:34 -0300 | [diff] [blame] | 300 | if (std == V4L2_STD_NTSC_443) |
Lars-Peter Clausen | f5dde49 | 2015-01-23 12:52:28 -0300 | [diff] [blame] | 301 | return ADV7180_STD_NTSC_443; |
Richard Röjfors | c277b60 | 2009-09-22 06:06:34 -0300 | [diff] [blame] | 302 | if (std == V4L2_STD_PAL_N) |
Lars-Peter Clausen | f5dde49 | 2015-01-23 12:52:28 -0300 | [diff] [blame] | 303 | return ADV7180_STD_PAL_N; |
Richard Röjfors | c277b60 | 2009-09-22 06:06:34 -0300 | [diff] [blame] | 304 | if (std == V4L2_STD_PAL_M) |
Lars-Peter Clausen | f5dde49 | 2015-01-23 12:52:28 -0300 | [diff] [blame] | 305 | return ADV7180_STD_PAL_M; |
Richard Röjfors | c277b60 | 2009-09-22 06:06:34 -0300 | [diff] [blame] | 306 | if (std == V4L2_STD_PAL_Nc) |
Lars-Peter Clausen | f5dde49 | 2015-01-23 12:52:28 -0300 | [diff] [blame] | 307 | return ADV7180_STD_PAL_COMB_N; |
Richard Röjfors | c277b60 | 2009-09-22 06:06:34 -0300 | [diff] [blame] | 308 | |
| 309 | if (std & V4L2_STD_PAL) |
Lars-Peter Clausen | f5dde49 | 2015-01-23 12:52:28 -0300 | [diff] [blame] | 310 | return ADV7180_STD_PAL_BG; |
Richard Röjfors | c277b60 | 2009-09-22 06:06:34 -0300 | [diff] [blame] | 311 | if (std & V4L2_STD_NTSC) |
Lars-Peter Clausen | f5dde49 | 2015-01-23 12:52:28 -0300 | [diff] [blame] | 312 | return ADV7180_STD_NTSC_M; |
Richard Röjfors | c277b60 | 2009-09-22 06:06:34 -0300 | [diff] [blame] | 313 | if (std & V4L2_STD_SECAM) |
Lars-Peter Clausen | f5dde49 | 2015-01-23 12:52:28 -0300 | [diff] [blame] | 314 | return ADV7180_STD_PAL_SECAM; |
Richard Röjfors | c277b60 | 2009-09-22 06:06:34 -0300 | [diff] [blame] | 315 | |
| 316 | return -EINVAL; |
| 317 | } |
| 318 | |
Richard Röjfors | d312429 | 2009-09-22 06:05:42 -0300 | [diff] [blame] | 319 | static u32 adv7180_status_to_v4l2(u8 status1) |
| 320 | { |
| 321 | if (!(status1 & ADV7180_STATUS1_IN_LOCK)) |
| 322 | return V4L2_IN_ST_NO_SIGNAL; |
| 323 | |
| 324 | return 0; |
| 325 | } |
| 326 | |
Lars-Peter Clausen | 3999e5d | 2015-01-23 12:52:24 -0300 | [diff] [blame] | 327 | static int __adv7180_status(struct adv7180_state *state, u32 *status, |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 328 | v4l2_std_id *std) |
Richard Röjfors | d312429 | 2009-09-22 06:05:42 -0300 | [diff] [blame] | 329 | { |
Lars-Peter Clausen | 3999e5d | 2015-01-23 12:52:24 -0300 | [diff] [blame] | 330 | int status1 = adv7180_read(state, ADV7180_REG_STATUS1); |
Richard Röjfors | d312429 | 2009-09-22 06:05:42 -0300 | [diff] [blame] | 331 | |
| 332 | if (status1 < 0) |
| 333 | return status1; |
| 334 | |
| 335 | if (status) |
| 336 | *status = adv7180_status_to_v4l2(status1); |
| 337 | if (std) |
| 338 | *std = adv7180_std_to_v4l2(status1); |
| 339 | |
| 340 | return 0; |
| 341 | } |
| 342 | |
Richard Röjfors | 6789cb5 | 2009-09-18 21:17:20 -0300 | [diff] [blame] | 343 | static inline struct adv7180_state *to_state(struct v4l2_subdev *sd) |
| 344 | { |
| 345 | return container_of(sd, struct adv7180_state, sd); |
| 346 | } |
| 347 | |
| 348 | static int adv7180_querystd(struct v4l2_subdev *sd, v4l2_std_id *std) |
| 349 | { |
Richard Röjfors | c277b60 | 2009-09-22 06:06:34 -0300 | [diff] [blame] | 350 | struct adv7180_state *state = to_state(sd); |
Richard Röjfors | 42752f7 | 2009-09-22 06:07:06 -0300 | [diff] [blame] | 351 | int err = mutex_lock_interruptible(&state->mutex); |
| 352 | if (err) |
| 353 | return err; |
Richard Röjfors | c277b60 | 2009-09-22 06:06:34 -0300 | [diff] [blame] | 354 | |
Hans Verkuil | 937feee | 2016-04-22 10:03:37 -0300 | [diff] [blame] | 355 | if (state->streaming) { |
| 356 | err = -EBUSY; |
| 357 | goto unlock; |
| 358 | } |
Richard Röjfors | c277b60 | 2009-09-22 06:06:34 -0300 | [diff] [blame] | 359 | |
Hans Verkuil | 937feee | 2016-04-22 10:03:37 -0300 | [diff] [blame] | 360 | err = adv7180_set_video_standard(state, |
| 361 | ADV7180_STD_AD_PAL_BG_NTSC_J_SECAM); |
| 362 | if (err) |
| 363 | goto unlock; |
| 364 | |
| 365 | msleep(100); |
| 366 | __adv7180_status(state, NULL, std); |
| 367 | |
| 368 | err = v4l2_std_to_adv7180(state->curr_norm); |
| 369 | if (err < 0) |
| 370 | goto unlock; |
| 371 | |
| 372 | err = adv7180_set_video_standard(state, err); |
| 373 | |
| 374 | unlock: |
Richard Röjfors | 42752f7 | 2009-09-22 06:07:06 -0300 | [diff] [blame] | 375 | mutex_unlock(&state->mutex); |
Richard Röjfors | c277b60 | 2009-09-22 06:06:34 -0300 | [diff] [blame] | 376 | return err; |
Richard Röjfors | d312429 | 2009-09-22 06:05:42 -0300 | [diff] [blame] | 377 | } |
Richard Röjfors | 6789cb5 | 2009-09-18 21:17:20 -0300 | [diff] [blame] | 378 | |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 379 | static int adv7180_s_routing(struct v4l2_subdev *sd, u32 input, |
| 380 | u32 output, u32 config) |
| 381 | { |
| 382 | struct adv7180_state *state = to_state(sd); |
| 383 | int ret = mutex_lock_interruptible(&state->mutex); |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 384 | |
| 385 | if (ret) |
| 386 | return ret; |
| 387 | |
Lars-Peter Clausen | f5dde49 | 2015-01-23 12:52:28 -0300 | [diff] [blame] | 388 | if (input > 31 || !(BIT(input) & state->chip_info->valid_input_mask)) { |
| 389 | ret = -EINVAL; |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 390 | goto out; |
Lars-Peter Clausen | f5dde49 | 2015-01-23 12:52:28 -0300 | [diff] [blame] | 391 | } |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 392 | |
Lars-Peter Clausen | f5dde49 | 2015-01-23 12:52:28 -0300 | [diff] [blame] | 393 | ret = state->chip_info->select_input(state, input); |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 394 | |
Lars-Peter Clausen | f5dde49 | 2015-01-23 12:52:28 -0300 | [diff] [blame] | 395 | if (ret == 0) |
| 396 | state->input = input; |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 397 | out: |
| 398 | mutex_unlock(&state->mutex); |
| 399 | return ret; |
| 400 | } |
| 401 | |
Richard Röjfors | d312429 | 2009-09-22 06:05:42 -0300 | [diff] [blame] | 402 | static int adv7180_g_input_status(struct v4l2_subdev *sd, u32 *status) |
| 403 | { |
Richard Röjfors | 42752f7 | 2009-09-22 06:07:06 -0300 | [diff] [blame] | 404 | struct adv7180_state *state = to_state(sd); |
| 405 | int ret = mutex_lock_interruptible(&state->mutex); |
| 406 | if (ret) |
| 407 | return ret; |
| 408 | |
Lars-Peter Clausen | 3999e5d | 2015-01-23 12:52:24 -0300 | [diff] [blame] | 409 | ret = __adv7180_status(state, status, NULL); |
Richard Röjfors | 42752f7 | 2009-09-22 06:07:06 -0300 | [diff] [blame] | 410 | mutex_unlock(&state->mutex); |
| 411 | return ret; |
Richard Röjfors | 6789cb5 | 2009-09-18 21:17:20 -0300 | [diff] [blame] | 412 | } |
| 413 | |
Lars-Peter Clausen | 3e35e33 | 2015-01-23 12:52:27 -0300 | [diff] [blame] | 414 | static int adv7180_program_std(struct adv7180_state *state) |
| 415 | { |
| 416 | int ret; |
| 417 | |
Hans Verkuil | 937feee | 2016-04-22 10:03:37 -0300 | [diff] [blame] | 418 | ret = v4l2_std_to_adv7180(state->curr_norm); |
| 419 | if (ret < 0) |
| 420 | return ret; |
Lars-Peter Clausen | 3e35e33 | 2015-01-23 12:52:27 -0300 | [diff] [blame] | 421 | |
Hans Verkuil | 937feee | 2016-04-22 10:03:37 -0300 | [diff] [blame] | 422 | ret = adv7180_set_video_standard(state, ret); |
| 423 | if (ret < 0) |
| 424 | return ret; |
Lars-Peter Clausen | 3e35e33 | 2015-01-23 12:52:27 -0300 | [diff] [blame] | 425 | return 0; |
| 426 | } |
| 427 | |
Richard Röjfors | c277b60 | 2009-09-22 06:06:34 -0300 | [diff] [blame] | 428 | static int adv7180_s_std(struct v4l2_subdev *sd, v4l2_std_id std) |
| 429 | { |
| 430 | struct adv7180_state *state = to_state(sd); |
Richard Röjfors | 42752f7 | 2009-09-22 06:07:06 -0300 | [diff] [blame] | 431 | int ret = mutex_lock_interruptible(&state->mutex); |
Lars-Peter Clausen | 3e35e33 | 2015-01-23 12:52:27 -0300 | [diff] [blame] | 432 | |
Richard Röjfors | 42752f7 | 2009-09-22 06:07:06 -0300 | [diff] [blame] | 433 | if (ret) |
| 434 | return ret; |
Richard Röjfors | c277b60 | 2009-09-22 06:06:34 -0300 | [diff] [blame] | 435 | |
Hans Verkuil | 937feee | 2016-04-22 10:03:37 -0300 | [diff] [blame] | 436 | /* Make sure we can support this std */ |
| 437 | ret = v4l2_std_to_adv7180(std); |
| 438 | if (ret < 0) |
| 439 | goto out; |
Richard Röjfors | c277b60 | 2009-09-22 06:06:34 -0300 | [diff] [blame] | 440 | |
Hans Verkuil | 937feee | 2016-04-22 10:03:37 -0300 | [diff] [blame] | 441 | state->curr_norm = std; |
Lars-Peter Clausen | 3e35e33 | 2015-01-23 12:52:27 -0300 | [diff] [blame] | 442 | |
| 443 | ret = adv7180_program_std(state); |
Richard Röjfors | c277b60 | 2009-09-22 06:06:34 -0300 | [diff] [blame] | 444 | out: |
Richard Röjfors | 42752f7 | 2009-09-22 06:07:06 -0300 | [diff] [blame] | 445 | mutex_unlock(&state->mutex); |
Richard Röjfors | c277b60 | 2009-09-22 06:06:34 -0300 | [diff] [blame] | 446 | return ret; |
| 447 | } |
| 448 | |
Niklas Söderlund | d0fadc8 | 2016-04-02 14:42:18 -0300 | [diff] [blame] | 449 | static int adv7180_g_std(struct v4l2_subdev *sd, v4l2_std_id *norm) |
| 450 | { |
| 451 | struct adv7180_state *state = to_state(sd); |
| 452 | |
| 453 | *norm = state->curr_norm; |
| 454 | |
| 455 | return 0; |
| 456 | } |
| 457 | |
Niklas Söderlund | 38566d2 | 2018-07-26 06:27:16 -0400 | [diff] [blame] | 458 | static int adv7180_g_frame_interval(struct v4l2_subdev *sd, |
| 459 | struct v4l2_subdev_frame_interval *fi) |
| 460 | { |
| 461 | struct adv7180_state *state = to_state(sd); |
| 462 | |
| 463 | if (state->curr_norm & V4L2_STD_525_60) { |
| 464 | fi->interval.numerator = 1001; |
| 465 | fi->interval.denominator = 30000; |
| 466 | } else { |
| 467 | fi->interval.numerator = 1; |
| 468 | fi->interval.denominator = 25; |
| 469 | } |
| 470 | |
| 471 | return 0; |
| 472 | } |
| 473 | |
Steve Longerbeam | 65d9e14 | 2016-07-19 21:03:32 -0300 | [diff] [blame] | 474 | static void adv7180_set_power_pin(struct adv7180_state *state, bool on) |
| 475 | { |
| 476 | if (!state->pwdn_gpio) |
| 477 | return; |
| 478 | |
| 479 | if (on) { |
| 480 | gpiod_set_value_cansleep(state->pwdn_gpio, 0); |
| 481 | usleep_range(5000, 10000); |
| 482 | } else { |
| 483 | gpiod_set_value_cansleep(state->pwdn_gpio, 1); |
| 484 | } |
| 485 | } |
| 486 | |
Lars-Peter Clausen | 3999e5d | 2015-01-23 12:52:24 -0300 | [diff] [blame] | 487 | static int adv7180_set_power(struct adv7180_state *state, bool on) |
Lars-Peter Clausen | e246c33 | 2014-03-10 14:05:39 -0300 | [diff] [blame] | 488 | { |
| 489 | u8 val; |
Lars-Peter Clausen | b37135e | 2015-01-23 12:52:31 -0300 | [diff] [blame] | 490 | int ret; |
Lars-Peter Clausen | e246c33 | 2014-03-10 14:05:39 -0300 | [diff] [blame] | 491 | |
| 492 | if (on) |
| 493 | val = ADV7180_PWR_MAN_ON; |
| 494 | else |
| 495 | val = ADV7180_PWR_MAN_OFF; |
| 496 | |
Lars-Peter Clausen | b37135e | 2015-01-23 12:52:31 -0300 | [diff] [blame] | 497 | ret = adv7180_write(state, ADV7180_REG_PWR_MAN, val); |
| 498 | if (ret) |
| 499 | return ret; |
| 500 | |
| 501 | if (state->chip_info->flags & ADV7180_FLAG_MIPI_CSI2) { |
| 502 | if (on) { |
| 503 | adv7180_csi_write(state, 0xDE, 0x02); |
| 504 | adv7180_csi_write(state, 0xD2, 0xF7); |
| 505 | adv7180_csi_write(state, 0xD8, 0x65); |
| 506 | adv7180_csi_write(state, 0xE0, 0x09); |
| 507 | adv7180_csi_write(state, 0x2C, 0x00); |
Lars-Peter Clausen | 851a54e | 2015-01-23 12:52:32 -0300 | [diff] [blame] | 508 | if (state->field == V4L2_FIELD_NONE) |
| 509 | adv7180_csi_write(state, 0x1D, 0x80); |
Lars-Peter Clausen | b37135e | 2015-01-23 12:52:31 -0300 | [diff] [blame] | 510 | adv7180_csi_write(state, 0x00, 0x00); |
| 511 | } else { |
| 512 | adv7180_csi_write(state, 0x00, 0x80); |
| 513 | } |
| 514 | } |
| 515 | |
| 516 | return 0; |
Lars-Peter Clausen | e246c33 | 2014-03-10 14:05:39 -0300 | [diff] [blame] | 517 | } |
| 518 | |
| 519 | static int adv7180_s_power(struct v4l2_subdev *sd, int on) |
| 520 | { |
| 521 | struct adv7180_state *state = to_state(sd); |
Lars-Peter Clausen | e246c33 | 2014-03-10 14:05:39 -0300 | [diff] [blame] | 522 | int ret; |
| 523 | |
| 524 | ret = mutex_lock_interruptible(&state->mutex); |
| 525 | if (ret) |
| 526 | return ret; |
| 527 | |
Lars-Peter Clausen | 3999e5d | 2015-01-23 12:52:24 -0300 | [diff] [blame] | 528 | ret = adv7180_set_power(state, on); |
Lars-Peter Clausen | e246c33 | 2014-03-10 14:05:39 -0300 | [diff] [blame] | 529 | if (ret == 0) |
| 530 | state->powered = on; |
| 531 | |
| 532 | mutex_unlock(&state->mutex); |
| 533 | return ret; |
| 534 | } |
| 535 | |
Federico Vaga | c9fbedd | 2012-07-11 11:29:33 -0300 | [diff] [blame] | 536 | static int adv7180_s_ctrl(struct v4l2_ctrl *ctrl) |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 537 | { |
Federico Vaga | c9fbedd | 2012-07-11 11:29:33 -0300 | [diff] [blame] | 538 | struct v4l2_subdev *sd = to_adv7180_sd(ctrl); |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 539 | struct adv7180_state *state = to_state(sd); |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 540 | int ret = mutex_lock_interruptible(&state->mutex); |
Federico Vaga | c9fbedd | 2012-07-11 11:29:33 -0300 | [diff] [blame] | 541 | int val; |
| 542 | |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 543 | if (ret) |
| 544 | return ret; |
Federico Vaga | c9fbedd | 2012-07-11 11:29:33 -0300 | [diff] [blame] | 545 | val = ctrl->val; |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 546 | switch (ctrl->id) { |
| 547 | case V4L2_CID_BRIGHTNESS: |
Lars-Peter Clausen | 3999e5d | 2015-01-23 12:52:24 -0300 | [diff] [blame] | 548 | ret = adv7180_write(state, ADV7180_REG_BRI, val); |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 549 | break; |
| 550 | case V4L2_CID_HUE: |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 551 | /*Hue is inverted according to HSL chart */ |
Lars-Peter Clausen | 3999e5d | 2015-01-23 12:52:24 -0300 | [diff] [blame] | 552 | ret = adv7180_write(state, ADV7180_REG_HUE, -val); |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 553 | break; |
| 554 | case V4L2_CID_CONTRAST: |
Lars-Peter Clausen | 3999e5d | 2015-01-23 12:52:24 -0300 | [diff] [blame] | 555 | ret = adv7180_write(state, ADV7180_REG_CON, val); |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 556 | break; |
| 557 | case V4L2_CID_SATURATION: |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 558 | /* |
| 559 | *This could be V4L2_CID_BLUE_BALANCE/V4L2_CID_RED_BALANCE |
| 560 | *Let's not confuse the user, everybody understands saturation |
| 561 | */ |
Lars-Peter Clausen | 3999e5d | 2015-01-23 12:52:24 -0300 | [diff] [blame] | 562 | ret = adv7180_write(state, ADV7180_REG_SD_SAT_CB, val); |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 563 | if (ret < 0) |
| 564 | break; |
Lars-Peter Clausen | 3999e5d | 2015-01-23 12:52:24 -0300 | [diff] [blame] | 565 | ret = adv7180_write(state, ADV7180_REG_SD_SAT_CR, val); |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 566 | break; |
Lars-Peter Clausen | 08b717c | 2015-01-23 12:52:33 -0300 | [diff] [blame] | 567 | case V4L2_CID_ADV_FAST_SWITCH: |
| 568 | if (ctrl->val) { |
| 569 | /* ADI required write */ |
| 570 | adv7180_write(state, 0x80d9, 0x44); |
| 571 | adv7180_write(state, ADV7180_REG_FLCONTROL, |
| 572 | ADV7180_FLCONTROL_FL_ENABLE); |
| 573 | } else { |
| 574 | /* ADI required write */ |
| 575 | adv7180_write(state, 0x80d9, 0xc4); |
| 576 | adv7180_write(state, ADV7180_REG_FLCONTROL, 0x00); |
| 577 | } |
| 578 | break; |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 579 | default: |
| 580 | ret = -EINVAL; |
| 581 | } |
| 582 | |
| 583 | mutex_unlock(&state->mutex); |
| 584 | return ret; |
| 585 | } |
| 586 | |
Federico Vaga | c9fbedd | 2012-07-11 11:29:33 -0300 | [diff] [blame] | 587 | static const struct v4l2_ctrl_ops adv7180_ctrl_ops = { |
| 588 | .s_ctrl = adv7180_s_ctrl, |
| 589 | }; |
| 590 | |
Lars-Peter Clausen | 08b717c | 2015-01-23 12:52:33 -0300 | [diff] [blame] | 591 | static const struct v4l2_ctrl_config adv7180_ctrl_fast_switch = { |
| 592 | .ops = &adv7180_ctrl_ops, |
| 593 | .id = V4L2_CID_ADV_FAST_SWITCH, |
| 594 | .name = "Fast Switching", |
| 595 | .type = V4L2_CTRL_TYPE_BOOLEAN, |
| 596 | .min = 0, |
| 597 | .max = 1, |
| 598 | .step = 1, |
| 599 | }; |
| 600 | |
Federico Vaga | c9fbedd | 2012-07-11 11:29:33 -0300 | [diff] [blame] | 601 | static int adv7180_init_controls(struct adv7180_state *state) |
| 602 | { |
| 603 | v4l2_ctrl_handler_init(&state->ctrl_hdl, 4); |
| 604 | |
| 605 | v4l2_ctrl_new_std(&state->ctrl_hdl, &adv7180_ctrl_ops, |
| 606 | V4L2_CID_BRIGHTNESS, ADV7180_BRI_MIN, |
| 607 | ADV7180_BRI_MAX, 1, ADV7180_BRI_DEF); |
| 608 | v4l2_ctrl_new_std(&state->ctrl_hdl, &adv7180_ctrl_ops, |
| 609 | V4L2_CID_CONTRAST, ADV7180_CON_MIN, |
| 610 | ADV7180_CON_MAX, 1, ADV7180_CON_DEF); |
| 611 | v4l2_ctrl_new_std(&state->ctrl_hdl, &adv7180_ctrl_ops, |
| 612 | V4L2_CID_SATURATION, ADV7180_SAT_MIN, |
| 613 | ADV7180_SAT_MAX, 1, ADV7180_SAT_DEF); |
| 614 | v4l2_ctrl_new_std(&state->ctrl_hdl, &adv7180_ctrl_ops, |
| 615 | V4L2_CID_HUE, ADV7180_HUE_MIN, |
| 616 | ADV7180_HUE_MAX, 1, ADV7180_HUE_DEF); |
Lars-Peter Clausen | 08b717c | 2015-01-23 12:52:33 -0300 | [diff] [blame] | 617 | v4l2_ctrl_new_custom(&state->ctrl_hdl, &adv7180_ctrl_fast_switch, NULL); |
| 618 | |
Federico Vaga | c9fbedd | 2012-07-11 11:29:33 -0300 | [diff] [blame] | 619 | state->sd.ctrl_handler = &state->ctrl_hdl; |
| 620 | if (state->ctrl_hdl.error) { |
| 621 | int err = state->ctrl_hdl.error; |
| 622 | |
| 623 | v4l2_ctrl_handler_free(&state->ctrl_hdl); |
| 624 | return err; |
| 625 | } |
| 626 | v4l2_ctrl_handler_setup(&state->ctrl_hdl); |
| 627 | |
| 628 | return 0; |
| 629 | } |
| 630 | static void adv7180_exit_controls(struct adv7180_state *state) |
| 631 | { |
| 632 | v4l2_ctrl_handler_free(&state->ctrl_hdl); |
| 633 | } |
| 634 | |
Lars-Peter Clausen | d5d51a8 | 2015-01-23 12:52:26 -0300 | [diff] [blame] | 635 | static int adv7180_enum_mbus_code(struct v4l2_subdev *sd, |
Hans Verkuil | f723413 | 2015-03-04 01:47:54 -0800 | [diff] [blame] | 636 | struct v4l2_subdev_pad_config *cfg, |
Lars-Peter Clausen | d5d51a8 | 2015-01-23 12:52:26 -0300 | [diff] [blame] | 637 | struct v4l2_subdev_mbus_code_enum *code) |
Vladimir Barinov | cccb83f | 2013-05-29 14:50:57 -0300 | [diff] [blame] | 638 | { |
Lars-Peter Clausen | d5d51a8 | 2015-01-23 12:52:26 -0300 | [diff] [blame] | 639 | if (code->index != 0) |
Vladimir Barinov | cccb83f | 2013-05-29 14:50:57 -0300 | [diff] [blame] | 640 | return -EINVAL; |
| 641 | |
Niklas Söderlund | 6de690d | 2016-09-02 12:37:06 -0300 | [diff] [blame] | 642 | code->code = MEDIA_BUS_FMT_UYVY8_2X8; |
Vladimir Barinov | cccb83f | 2013-05-29 14:50:57 -0300 | [diff] [blame] | 643 | |
| 644 | return 0; |
| 645 | } |
| 646 | |
| 647 | static int adv7180_mbus_fmt(struct v4l2_subdev *sd, |
| 648 | struct v4l2_mbus_framefmt *fmt) |
| 649 | { |
| 650 | struct adv7180_state *state = to_state(sd); |
| 651 | |
Niklas Söderlund | 6de690d | 2016-09-02 12:37:06 -0300 | [diff] [blame] | 652 | fmt->code = MEDIA_BUS_FMT_UYVY8_2X8; |
Vladimir Barinov | cccb83f | 2013-05-29 14:50:57 -0300 | [diff] [blame] | 653 | fmt->colorspace = V4L2_COLORSPACE_SMPTE170M; |
Vladimir Barinov | cccb83f | 2013-05-29 14:50:57 -0300 | [diff] [blame] | 654 | fmt->width = 720; |
| 655 | fmt->height = state->curr_norm & V4L2_STD_525_60 ? 480 : 576; |
| 656 | |
Niklas Söderlund | 6457b62 | 2018-07-26 06:27:15 -0400 | [diff] [blame] | 657 | if (state->field == V4L2_FIELD_ALTERNATE) |
| 658 | fmt->height /= 2; |
| 659 | |
Vladimir Barinov | cccb83f | 2013-05-29 14:50:57 -0300 | [diff] [blame] | 660 | return 0; |
| 661 | } |
| 662 | |
Lars-Peter Clausen | 851a54e | 2015-01-23 12:52:32 -0300 | [diff] [blame] | 663 | static int adv7180_set_field_mode(struct adv7180_state *state) |
| 664 | { |
| 665 | if (!(state->chip_info->flags & ADV7180_FLAG_I2P)) |
| 666 | return 0; |
| 667 | |
| 668 | if (state->field == V4L2_FIELD_NONE) { |
| 669 | if (state->chip_info->flags & ADV7180_FLAG_MIPI_CSI2) { |
| 670 | adv7180_csi_write(state, 0x01, 0x20); |
| 671 | adv7180_csi_write(state, 0x02, 0x28); |
| 672 | adv7180_csi_write(state, 0x03, 0x38); |
| 673 | adv7180_csi_write(state, 0x04, 0x30); |
| 674 | adv7180_csi_write(state, 0x05, 0x30); |
| 675 | adv7180_csi_write(state, 0x06, 0x80); |
| 676 | adv7180_csi_write(state, 0x07, 0x70); |
| 677 | adv7180_csi_write(state, 0x08, 0x50); |
| 678 | } |
| 679 | adv7180_vpp_write(state, 0xa3, 0x00); |
| 680 | adv7180_vpp_write(state, 0x5b, 0x00); |
| 681 | adv7180_vpp_write(state, 0x55, 0x80); |
| 682 | } else { |
| 683 | if (state->chip_info->flags & ADV7180_FLAG_MIPI_CSI2) { |
| 684 | adv7180_csi_write(state, 0x01, 0x18); |
| 685 | adv7180_csi_write(state, 0x02, 0x18); |
| 686 | adv7180_csi_write(state, 0x03, 0x30); |
| 687 | adv7180_csi_write(state, 0x04, 0x20); |
| 688 | adv7180_csi_write(state, 0x05, 0x28); |
| 689 | adv7180_csi_write(state, 0x06, 0x40); |
| 690 | adv7180_csi_write(state, 0x07, 0x58); |
| 691 | adv7180_csi_write(state, 0x08, 0x30); |
| 692 | } |
| 693 | adv7180_vpp_write(state, 0xa3, 0x70); |
| 694 | adv7180_vpp_write(state, 0x5b, 0x80); |
| 695 | adv7180_vpp_write(state, 0x55, 0x00); |
| 696 | } |
| 697 | |
| 698 | return 0; |
| 699 | } |
| 700 | |
Lars-Peter Clausen | d5d51a8 | 2015-01-23 12:52:26 -0300 | [diff] [blame] | 701 | static int adv7180_get_pad_format(struct v4l2_subdev *sd, |
Hans Verkuil | f723413 | 2015-03-04 01:47:54 -0800 | [diff] [blame] | 702 | struct v4l2_subdev_pad_config *cfg, |
Lars-Peter Clausen | d5d51a8 | 2015-01-23 12:52:26 -0300 | [diff] [blame] | 703 | struct v4l2_subdev_format *format) |
| 704 | { |
Lars-Peter Clausen | 851a54e | 2015-01-23 12:52:32 -0300 | [diff] [blame] | 705 | struct adv7180_state *state = to_state(sd); |
| 706 | |
| 707 | if (format->which == V4L2_SUBDEV_FORMAT_TRY) { |
Hans Verkuil | f723413 | 2015-03-04 01:47:54 -0800 | [diff] [blame] | 708 | format->format = *v4l2_subdev_get_try_format(sd, cfg, 0); |
Lars-Peter Clausen | 851a54e | 2015-01-23 12:52:32 -0300 | [diff] [blame] | 709 | } else { |
| 710 | adv7180_mbus_fmt(sd, &format->format); |
| 711 | format->format.field = state->field; |
| 712 | } |
| 713 | |
| 714 | return 0; |
Lars-Peter Clausen | d5d51a8 | 2015-01-23 12:52:26 -0300 | [diff] [blame] | 715 | } |
| 716 | |
| 717 | static int adv7180_set_pad_format(struct v4l2_subdev *sd, |
Hans Verkuil | f723413 | 2015-03-04 01:47:54 -0800 | [diff] [blame] | 718 | struct v4l2_subdev_pad_config *cfg, |
Lars-Peter Clausen | d5d51a8 | 2015-01-23 12:52:26 -0300 | [diff] [blame] | 719 | struct v4l2_subdev_format *format) |
| 720 | { |
Lars-Peter Clausen | 851a54e | 2015-01-23 12:52:32 -0300 | [diff] [blame] | 721 | struct adv7180_state *state = to_state(sd); |
| 722 | struct v4l2_mbus_framefmt *framefmt; |
Niklas Söderlund | e0ad7a9 | 2016-09-02 13:44:56 -0300 | [diff] [blame] | 723 | int ret; |
Lars-Peter Clausen | 851a54e | 2015-01-23 12:52:32 -0300 | [diff] [blame] | 724 | |
| 725 | switch (format->format.field) { |
| 726 | case V4L2_FIELD_NONE: |
Niklas Söderlund | 6457b62 | 2018-07-26 06:27:15 -0400 | [diff] [blame] | 727 | if (state->chip_info->flags & ADV7180_FLAG_I2P) |
| 728 | break; |
| 729 | /* fall through */ |
Lars-Peter Clausen | 851a54e | 2015-01-23 12:52:32 -0300 | [diff] [blame] | 730 | default: |
Niklas Söderlund | 6457b62 | 2018-07-26 06:27:15 -0400 | [diff] [blame] | 731 | format->format.field = V4L2_FIELD_ALTERNATE; |
Lars-Peter Clausen | 851a54e | 2015-01-23 12:52:32 -0300 | [diff] [blame] | 732 | break; |
| 733 | } |
| 734 | |
Niklas Söderlund | e0ad7a9 | 2016-09-02 13:44:56 -0300 | [diff] [blame] | 735 | ret = adv7180_mbus_fmt(sd, &format->format); |
| 736 | |
Lars-Peter Clausen | 851a54e | 2015-01-23 12:52:32 -0300 | [diff] [blame] | 737 | if (format->which == V4L2_SUBDEV_FORMAT_ACTIVE) { |
Lars-Peter Clausen | 851a54e | 2015-01-23 12:52:32 -0300 | [diff] [blame] | 738 | if (state->field != format->format.field) { |
| 739 | state->field = format->format.field; |
| 740 | adv7180_set_power(state, false); |
| 741 | adv7180_set_field_mode(state); |
| 742 | adv7180_set_power(state, true); |
| 743 | } |
| 744 | } else { |
Hans Verkuil | f723413 | 2015-03-04 01:47:54 -0800 | [diff] [blame] | 745 | framefmt = v4l2_subdev_get_try_format(sd, cfg, 0); |
Lars-Peter Clausen | 851a54e | 2015-01-23 12:52:32 -0300 | [diff] [blame] | 746 | *framefmt = format->format; |
| 747 | } |
| 748 | |
Niklas Söderlund | e0ad7a9 | 2016-09-02 13:44:56 -0300 | [diff] [blame] | 749 | return ret; |
Lars-Peter Clausen | d5d51a8 | 2015-01-23 12:52:26 -0300 | [diff] [blame] | 750 | } |
| 751 | |
Vladimir Barinov | cccb83f | 2013-05-29 14:50:57 -0300 | [diff] [blame] | 752 | static int adv7180_g_mbus_config(struct v4l2_subdev *sd, |
| 753 | struct v4l2_mbus_config *cfg) |
| 754 | { |
Lars-Peter Clausen | b37135e | 2015-01-23 12:52:31 -0300 | [diff] [blame] | 755 | struct adv7180_state *state = to_state(sd); |
| 756 | |
| 757 | if (state->chip_info->flags & ADV7180_FLAG_MIPI_CSI2) { |
Sakari Ailus | 2d95e7e | 2018-07-03 17:19:27 -0400 | [diff] [blame] | 758 | cfg->type = V4L2_MBUS_CSI2_DPHY; |
Lars-Peter Clausen | b37135e | 2015-01-23 12:52:31 -0300 | [diff] [blame] | 759 | cfg->flags = V4L2_MBUS_CSI2_1_LANE | |
| 760 | V4L2_MBUS_CSI2_CHANNEL_0 | |
| 761 | V4L2_MBUS_CSI2_CONTINUOUS_CLOCK; |
| 762 | } else { |
| 763 | /* |
| 764 | * The ADV7180 sensor supports BT.601/656 output modes. |
| 765 | * The BT.656 is default and not yet configurable by s/w. |
| 766 | */ |
| 767 | cfg->flags = V4L2_MBUS_MASTER | V4L2_MBUS_PCLK_SAMPLE_RISING | |
| 768 | V4L2_MBUS_DATA_ACTIVE_HIGH; |
| 769 | cfg->type = V4L2_MBUS_BT656; |
| 770 | } |
Vladimir Barinov | cccb83f | 2013-05-29 14:50:57 -0300 | [diff] [blame] | 771 | |
| 772 | return 0; |
| 773 | } |
| 774 | |
Tim Harvey | 9483a3f | 2018-10-24 16:25:51 -0400 | [diff] [blame] | 775 | static int adv7180_get_skip_frames(struct v4l2_subdev *sd, u32 *frames) |
| 776 | { |
| 777 | *frames = ADV7180_NUM_OF_SKIP_FRAMES; |
| 778 | |
| 779 | return 0; |
| 780 | } |
| 781 | |
Hans Verkuil | ecf3749 | 2016-07-04 05:08:01 -0300 | [diff] [blame] | 782 | static int adv7180_g_pixelaspect(struct v4l2_subdev *sd, struct v4l2_fract *aspect) |
Niklas Söderlund | 64b3df9 | 2016-04-02 14:42:19 -0300 | [diff] [blame] | 783 | { |
| 784 | struct adv7180_state *state = to_state(sd); |
| 785 | |
| 786 | if (state->curr_norm & V4L2_STD_525_60) { |
Hans Verkuil | ecf3749 | 2016-07-04 05:08:01 -0300 | [diff] [blame] | 787 | aspect->numerator = 11; |
| 788 | aspect->denominator = 10; |
Niklas Söderlund | 64b3df9 | 2016-04-02 14:42:19 -0300 | [diff] [blame] | 789 | } else { |
Hans Verkuil | ecf3749 | 2016-07-04 05:08:01 -0300 | [diff] [blame] | 790 | aspect->numerator = 54; |
| 791 | aspect->denominator = 59; |
Niklas Söderlund | 64b3df9 | 2016-04-02 14:42:19 -0300 | [diff] [blame] | 792 | } |
| 793 | |
| 794 | return 0; |
| 795 | } |
| 796 | |
Niklas Söderlund | bae4c75 | 2016-04-02 14:42:20 -0300 | [diff] [blame] | 797 | static int adv7180_g_tvnorms(struct v4l2_subdev *sd, v4l2_std_id *norm) |
| 798 | { |
| 799 | *norm = V4L2_STD_ALL; |
| 800 | return 0; |
| 801 | } |
| 802 | |
Hans Verkuil | 937feee | 2016-04-22 10:03:37 -0300 | [diff] [blame] | 803 | static int adv7180_s_stream(struct v4l2_subdev *sd, int enable) |
| 804 | { |
| 805 | struct adv7180_state *state = to_state(sd); |
| 806 | int ret; |
| 807 | |
| 808 | /* It's always safe to stop streaming, no need to take the lock */ |
| 809 | if (!enable) { |
| 810 | state->streaming = enable; |
| 811 | return 0; |
| 812 | } |
| 813 | |
| 814 | /* Must wait until querystd released the lock */ |
| 815 | ret = mutex_lock_interruptible(&state->mutex); |
| 816 | if (ret) |
| 817 | return ret; |
| 818 | state->streaming = enable; |
| 819 | mutex_unlock(&state->mutex); |
| 820 | return 0; |
| 821 | } |
| 822 | |
| 823 | static int adv7180_subscribe_event(struct v4l2_subdev *sd, |
| 824 | struct v4l2_fh *fh, |
| 825 | struct v4l2_event_subscription *sub) |
| 826 | { |
| 827 | switch (sub->type) { |
| 828 | case V4L2_EVENT_SOURCE_CHANGE: |
| 829 | return v4l2_src_change_event_subdev_subscribe(sd, fh, sub); |
| 830 | case V4L2_EVENT_CTRL: |
| 831 | return v4l2_ctrl_subdev_subscribe_event(sd, fh, sub); |
| 832 | default: |
| 833 | return -EINVAL; |
| 834 | } |
| 835 | } |
| 836 | |
Richard Röjfors | 6789cb5 | 2009-09-18 21:17:20 -0300 | [diff] [blame] | 837 | static const struct v4l2_subdev_video_ops adv7180_video_ops = { |
Laurent Pinchart | 8774bed | 2014-04-28 16:53:01 -0300 | [diff] [blame] | 838 | .s_std = adv7180_s_std, |
Niklas Söderlund | d0fadc8 | 2016-04-02 14:42:18 -0300 | [diff] [blame] | 839 | .g_std = adv7180_g_std, |
Niklas Söderlund | 38566d2 | 2018-07-26 06:27:16 -0400 | [diff] [blame] | 840 | .g_frame_interval = adv7180_g_frame_interval, |
Richard Röjfors | 6789cb5 | 2009-09-18 21:17:20 -0300 | [diff] [blame] | 841 | .querystd = adv7180_querystd, |
Richard Röjfors | d312429 | 2009-09-22 06:05:42 -0300 | [diff] [blame] | 842 | .g_input_status = adv7180_g_input_status, |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 843 | .s_routing = adv7180_s_routing, |
Vladimir Barinov | cccb83f | 2013-05-29 14:50:57 -0300 | [diff] [blame] | 844 | .g_mbus_config = adv7180_g_mbus_config, |
Hans Verkuil | ecf3749 | 2016-07-04 05:08:01 -0300 | [diff] [blame] | 845 | .g_pixelaspect = adv7180_g_pixelaspect, |
Niklas Söderlund | bae4c75 | 2016-04-02 14:42:20 -0300 | [diff] [blame] | 846 | .g_tvnorms = adv7180_g_tvnorms, |
Hans Verkuil | 937feee | 2016-04-22 10:03:37 -0300 | [diff] [blame] | 847 | .s_stream = adv7180_s_stream, |
Richard Röjfors | 6789cb5 | 2009-09-18 21:17:20 -0300 | [diff] [blame] | 848 | }; |
| 849 | |
| 850 | static const struct v4l2_subdev_core_ops adv7180_core_ops = { |
Lars-Peter Clausen | e246c33 | 2014-03-10 14:05:39 -0300 | [diff] [blame] | 851 | .s_power = adv7180_s_power, |
Hans Verkuil | 937feee | 2016-04-22 10:03:37 -0300 | [diff] [blame] | 852 | .subscribe_event = adv7180_subscribe_event, |
| 853 | .unsubscribe_event = v4l2_event_subdev_unsubscribe, |
Richard Röjfors | 6789cb5 | 2009-09-18 21:17:20 -0300 | [diff] [blame] | 854 | }; |
| 855 | |
Lars-Peter Clausen | d5d51a8 | 2015-01-23 12:52:26 -0300 | [diff] [blame] | 856 | static const struct v4l2_subdev_pad_ops adv7180_pad_ops = { |
| 857 | .enum_mbus_code = adv7180_enum_mbus_code, |
| 858 | .set_fmt = adv7180_set_pad_format, |
| 859 | .get_fmt = adv7180_get_pad_format, |
| 860 | }; |
| 861 | |
Tim Harvey | 9483a3f | 2018-10-24 16:25:51 -0400 | [diff] [blame] | 862 | static const struct v4l2_subdev_sensor_ops adv7180_sensor_ops = { |
| 863 | .g_skip_frames = adv7180_get_skip_frames, |
| 864 | }; |
| 865 | |
Richard Röjfors | 6789cb5 | 2009-09-18 21:17:20 -0300 | [diff] [blame] | 866 | static const struct v4l2_subdev_ops adv7180_ops = { |
| 867 | .core = &adv7180_core_ops, |
| 868 | .video = &adv7180_video_ops, |
Lars-Peter Clausen | d5d51a8 | 2015-01-23 12:52:26 -0300 | [diff] [blame] | 869 | .pad = &adv7180_pad_ops, |
Tim Harvey | 9483a3f | 2018-10-24 16:25:51 -0400 | [diff] [blame] | 870 | .sensor = &adv7180_sensor_ops, |
Richard Röjfors | 6789cb5 | 2009-09-18 21:17:20 -0300 | [diff] [blame] | 871 | }; |
| 872 | |
Lars-Peter Clausen | 0c25534 | 2014-03-07 13:14:31 -0300 | [diff] [blame] | 873 | static irqreturn_t adv7180_irq(int irq, void *devid) |
Richard Röjfors | 42752f7 | 2009-09-22 06:07:06 -0300 | [diff] [blame] | 874 | { |
Lars-Peter Clausen | 0c25534 | 2014-03-07 13:14:31 -0300 | [diff] [blame] | 875 | struct adv7180_state *state = devid; |
Richard Röjfors | 42752f7 | 2009-09-22 06:07:06 -0300 | [diff] [blame] | 876 | u8 isr3; |
| 877 | |
| 878 | mutex_lock(&state->mutex); |
Lars-Peter Clausen | 3999e5d | 2015-01-23 12:52:24 -0300 | [diff] [blame] | 879 | isr3 = adv7180_read(state, ADV7180_REG_ISR3); |
Richard Röjfors | 42752f7 | 2009-09-22 06:07:06 -0300 | [diff] [blame] | 880 | /* clear */ |
Lars-Peter Clausen | 3999e5d | 2015-01-23 12:52:24 -0300 | [diff] [blame] | 881 | adv7180_write(state, ADV7180_REG_ICR3, isr3); |
Richard Röjfors | 42752f7 | 2009-09-22 06:07:06 -0300 | [diff] [blame] | 882 | |
Hans Verkuil | 937feee | 2016-04-22 10:03:37 -0300 | [diff] [blame] | 883 | if (isr3 & ADV7180_IRQ3_AD_CHANGE) { |
| 884 | static const struct v4l2_event src_ch = { |
| 885 | .type = V4L2_EVENT_SOURCE_CHANGE, |
| 886 | .u.src_change.changes = V4L2_EVENT_SRC_CH_RESOLUTION, |
| 887 | }; |
| 888 | |
| 889 | v4l2_subdev_notify_event(&state->sd, &src_ch); |
| 890 | } |
Richard Röjfors | 42752f7 | 2009-09-22 06:07:06 -0300 | [diff] [blame] | 891 | mutex_unlock(&state->mutex); |
| 892 | |
Richard Röjfors | 42752f7 | 2009-09-22 06:07:06 -0300 | [diff] [blame] | 893 | return IRQ_HANDLED; |
| 894 | } |
| 895 | |
Lars-Peter Clausen | f5dde49 | 2015-01-23 12:52:28 -0300 | [diff] [blame] | 896 | static int adv7180_init(struct adv7180_state *state) |
| 897 | { |
| 898 | int ret; |
| 899 | |
| 900 | /* ITU-R BT.656-4 compatible */ |
| 901 | ret = adv7180_write(state, ADV7180_REG_EXTENDED_OUTPUT_CONTROL, |
| 902 | ADV7180_EXTENDED_OUTPUT_CONTROL_NTSCDIS); |
| 903 | if (ret < 0) |
| 904 | return ret; |
| 905 | |
| 906 | /* Manually set V bit end position in NTSC mode */ |
| 907 | return adv7180_write(state, ADV7180_REG_NTSC_V_BIT_END, |
| 908 | ADV7180_NTSC_V_BIT_END_MANUAL_NVEND); |
| 909 | } |
| 910 | |
| 911 | static int adv7180_set_std(struct adv7180_state *state, unsigned int std) |
| 912 | { |
| 913 | return adv7180_write(state, ADV7180_REG_INPUT_CONTROL, |
| 914 | (std << 4) | state->input); |
| 915 | } |
| 916 | |
| 917 | static int adv7180_select_input(struct adv7180_state *state, unsigned int input) |
| 918 | { |
| 919 | int ret; |
| 920 | |
| 921 | ret = adv7180_read(state, ADV7180_REG_INPUT_CONTROL); |
| 922 | if (ret < 0) |
| 923 | return ret; |
| 924 | |
| 925 | ret &= ~ADV7180_INPUT_CONTROL_INSEL_MASK; |
| 926 | ret |= input; |
| 927 | return adv7180_write(state, ADV7180_REG_INPUT_CONTROL, ret); |
| 928 | } |
| 929 | |
Lars-Peter Clausen | c5ef8f8 | 2015-01-23 12:52:29 -0300 | [diff] [blame] | 930 | static int adv7182_init(struct adv7180_state *state) |
| 931 | { |
Lars-Peter Clausen | b37135e | 2015-01-23 12:52:31 -0300 | [diff] [blame] | 932 | if (state->chip_info->flags & ADV7180_FLAG_MIPI_CSI2) |
| 933 | adv7180_write(state, ADV7180_REG_CSI_SLAVE_ADDR, |
| 934 | ADV7180_DEFAULT_CSI_I2C_ADDR << 1); |
| 935 | |
Lars-Peter Clausen | 851a54e | 2015-01-23 12:52:32 -0300 | [diff] [blame] | 936 | if (state->chip_info->flags & ADV7180_FLAG_I2P) |
| 937 | adv7180_write(state, ADV7180_REG_VPP_SLAVE_ADDR, |
| 938 | ADV7180_DEFAULT_VPP_I2C_ADDR << 1); |
| 939 | |
Lars-Peter Clausen | bf7dcb8 | 2015-01-23 12:52:30 -0300 | [diff] [blame] | 940 | if (state->chip_info->flags & ADV7180_FLAG_V2) { |
| 941 | /* ADI recommended writes for improved video quality */ |
| 942 | adv7180_write(state, 0x0080, 0x51); |
| 943 | adv7180_write(state, 0x0081, 0x51); |
| 944 | adv7180_write(state, 0x0082, 0x68); |
Lars-Peter Clausen | bf7dcb8 | 2015-01-23 12:52:30 -0300 | [diff] [blame] | 945 | } |
| 946 | |
Lars-Peter Clausen | c5ef8f8 | 2015-01-23 12:52:29 -0300 | [diff] [blame] | 947 | /* ADI required writes */ |
Lars-Peter Clausen | b37135e | 2015-01-23 12:52:31 -0300 | [diff] [blame] | 948 | if (state->chip_info->flags & ADV7180_FLAG_MIPI_CSI2) { |
Steve Longerbeam | ce5d629 | 2016-07-19 21:03:30 -0300 | [diff] [blame] | 949 | adv7180_write(state, ADV7180_REG_OUTPUT_CONTROL, 0x4e); |
| 950 | adv7180_write(state, ADV7180_REG_EXTENDED_OUTPUT_CONTROL, 0x57); |
| 951 | adv7180_write(state, ADV7180_REG_CTRL_2, 0xc0); |
Lars-Peter Clausen | b37135e | 2015-01-23 12:52:31 -0300 | [diff] [blame] | 952 | } else { |
| 953 | if (state->chip_info->flags & ADV7180_FLAG_V2) |
Steve Longerbeam | ce5d629 | 2016-07-19 21:03:30 -0300 | [diff] [blame] | 954 | adv7180_write(state, |
| 955 | ADV7180_REG_EXTENDED_OUTPUT_CONTROL, |
| 956 | 0x17); |
Lars-Peter Clausen | b37135e | 2015-01-23 12:52:31 -0300 | [diff] [blame] | 957 | else |
Steve Longerbeam | ce5d629 | 2016-07-19 21:03:30 -0300 | [diff] [blame] | 958 | adv7180_write(state, |
| 959 | ADV7180_REG_EXTENDED_OUTPUT_CONTROL, |
| 960 | 0x07); |
| 961 | adv7180_write(state, ADV7180_REG_OUTPUT_CONTROL, 0x0c); |
| 962 | adv7180_write(state, ADV7180_REG_CTRL_2, 0x40); |
Lars-Peter Clausen | b37135e | 2015-01-23 12:52:31 -0300 | [diff] [blame] | 963 | } |
| 964 | |
Lars-Peter Clausen | c5ef8f8 | 2015-01-23 12:52:29 -0300 | [diff] [blame] | 965 | adv7180_write(state, 0x0013, 0x00); |
Lars-Peter Clausen | c5ef8f8 | 2015-01-23 12:52:29 -0300 | [diff] [blame] | 966 | |
| 967 | return 0; |
| 968 | } |
| 969 | |
| 970 | static int adv7182_set_std(struct adv7180_state *state, unsigned int std) |
| 971 | { |
| 972 | return adv7180_write(state, ADV7182_REG_INPUT_VIDSEL, std << 4); |
| 973 | } |
| 974 | |
| 975 | enum adv7182_input_type { |
| 976 | ADV7182_INPUT_TYPE_CVBS, |
| 977 | ADV7182_INPUT_TYPE_DIFF_CVBS, |
| 978 | ADV7182_INPUT_TYPE_SVIDEO, |
| 979 | ADV7182_INPUT_TYPE_YPBPR, |
| 980 | }; |
| 981 | |
| 982 | static enum adv7182_input_type adv7182_get_input_type(unsigned int input) |
| 983 | { |
| 984 | switch (input) { |
| 985 | case ADV7182_INPUT_CVBS_AIN1: |
| 986 | case ADV7182_INPUT_CVBS_AIN2: |
| 987 | case ADV7182_INPUT_CVBS_AIN3: |
| 988 | case ADV7182_INPUT_CVBS_AIN4: |
| 989 | case ADV7182_INPUT_CVBS_AIN5: |
| 990 | case ADV7182_INPUT_CVBS_AIN6: |
| 991 | case ADV7182_INPUT_CVBS_AIN7: |
| 992 | case ADV7182_INPUT_CVBS_AIN8: |
| 993 | return ADV7182_INPUT_TYPE_CVBS; |
| 994 | case ADV7182_INPUT_SVIDEO_AIN1_AIN2: |
| 995 | case ADV7182_INPUT_SVIDEO_AIN3_AIN4: |
| 996 | case ADV7182_INPUT_SVIDEO_AIN5_AIN6: |
| 997 | case ADV7182_INPUT_SVIDEO_AIN7_AIN8: |
| 998 | return ADV7182_INPUT_TYPE_SVIDEO; |
| 999 | case ADV7182_INPUT_YPRPB_AIN1_AIN2_AIN3: |
| 1000 | case ADV7182_INPUT_YPRPB_AIN4_AIN5_AIN6: |
| 1001 | return ADV7182_INPUT_TYPE_YPBPR; |
| 1002 | case ADV7182_INPUT_DIFF_CVBS_AIN1_AIN2: |
| 1003 | case ADV7182_INPUT_DIFF_CVBS_AIN3_AIN4: |
| 1004 | case ADV7182_INPUT_DIFF_CVBS_AIN5_AIN6: |
| 1005 | case ADV7182_INPUT_DIFF_CVBS_AIN7_AIN8: |
| 1006 | return ADV7182_INPUT_TYPE_DIFF_CVBS; |
| 1007 | default: /* Will never happen */ |
| 1008 | return 0; |
| 1009 | } |
| 1010 | } |
| 1011 | |
| 1012 | /* ADI recommended writes to registers 0x52, 0x53, 0x54 */ |
| 1013 | static unsigned int adv7182_lbias_settings[][3] = { |
| 1014 | [ADV7182_INPUT_TYPE_CVBS] = { 0xCB, 0x4E, 0x80 }, |
| 1015 | [ADV7182_INPUT_TYPE_DIFF_CVBS] = { 0xC0, 0x4E, 0x80 }, |
| 1016 | [ADV7182_INPUT_TYPE_SVIDEO] = { 0x0B, 0xCE, 0x80 }, |
| 1017 | [ADV7182_INPUT_TYPE_YPBPR] = { 0x0B, 0x4E, 0xC0 }, |
| 1018 | }; |
| 1019 | |
Lars-Peter Clausen | bf7dcb8 | 2015-01-23 12:52:30 -0300 | [diff] [blame] | 1020 | static unsigned int adv7280_lbias_settings[][3] = { |
| 1021 | [ADV7182_INPUT_TYPE_CVBS] = { 0xCD, 0x4E, 0x80 }, |
| 1022 | [ADV7182_INPUT_TYPE_DIFF_CVBS] = { 0xC0, 0x4E, 0x80 }, |
| 1023 | [ADV7182_INPUT_TYPE_SVIDEO] = { 0x0B, 0xCE, 0x80 }, |
| 1024 | [ADV7182_INPUT_TYPE_YPBPR] = { 0x0B, 0x4E, 0xC0 }, |
| 1025 | }; |
| 1026 | |
Lars-Peter Clausen | c5ef8f8 | 2015-01-23 12:52:29 -0300 | [diff] [blame] | 1027 | static int adv7182_select_input(struct adv7180_state *state, unsigned int input) |
| 1028 | { |
| 1029 | enum adv7182_input_type input_type; |
| 1030 | unsigned int *lbias; |
| 1031 | unsigned int i; |
| 1032 | int ret; |
| 1033 | |
| 1034 | ret = adv7180_write(state, ADV7180_REG_INPUT_CONTROL, input); |
| 1035 | if (ret) |
| 1036 | return ret; |
| 1037 | |
| 1038 | /* Reset clamp circuitry - ADI recommended writes */ |
Steve Longerbeam | ce5d629 | 2016-07-19 21:03:30 -0300 | [diff] [blame] | 1039 | adv7180_write(state, ADV7180_REG_RST_CLAMP, 0x00); |
| 1040 | adv7180_write(state, ADV7180_REG_RST_CLAMP, 0xff); |
Lars-Peter Clausen | c5ef8f8 | 2015-01-23 12:52:29 -0300 | [diff] [blame] | 1041 | |
| 1042 | input_type = adv7182_get_input_type(input); |
| 1043 | |
| 1044 | switch (input_type) { |
| 1045 | case ADV7182_INPUT_TYPE_CVBS: |
| 1046 | case ADV7182_INPUT_TYPE_DIFF_CVBS: |
| 1047 | /* ADI recommends to use the SH1 filter */ |
Steve Longerbeam | ce5d629 | 2016-07-19 21:03:30 -0300 | [diff] [blame] | 1048 | adv7180_write(state, ADV7180_REG_SHAP_FILTER_CTL_1, 0x41); |
Lars-Peter Clausen | c5ef8f8 | 2015-01-23 12:52:29 -0300 | [diff] [blame] | 1049 | break; |
| 1050 | default: |
Steve Longerbeam | ce5d629 | 2016-07-19 21:03:30 -0300 | [diff] [blame] | 1051 | adv7180_write(state, ADV7180_REG_SHAP_FILTER_CTL_1, 0x01); |
Lars-Peter Clausen | c5ef8f8 | 2015-01-23 12:52:29 -0300 | [diff] [blame] | 1052 | break; |
| 1053 | } |
| 1054 | |
Lars-Peter Clausen | bf7dcb8 | 2015-01-23 12:52:30 -0300 | [diff] [blame] | 1055 | if (state->chip_info->flags & ADV7180_FLAG_V2) |
| 1056 | lbias = adv7280_lbias_settings[input_type]; |
| 1057 | else |
| 1058 | lbias = adv7182_lbias_settings[input_type]; |
Lars-Peter Clausen | c5ef8f8 | 2015-01-23 12:52:29 -0300 | [diff] [blame] | 1059 | |
| 1060 | for (i = 0; i < ARRAY_SIZE(adv7182_lbias_settings[0]); i++) |
Steve Longerbeam | ce5d629 | 2016-07-19 21:03:30 -0300 | [diff] [blame] | 1061 | adv7180_write(state, ADV7180_REG_CVBS_TRIM + i, lbias[i]); |
Lars-Peter Clausen | c5ef8f8 | 2015-01-23 12:52:29 -0300 | [diff] [blame] | 1062 | |
| 1063 | if (input_type == ADV7182_INPUT_TYPE_DIFF_CVBS) { |
| 1064 | /* ADI required writes to make differential CVBS work */ |
Steve Longerbeam | ce5d629 | 2016-07-19 21:03:30 -0300 | [diff] [blame] | 1065 | adv7180_write(state, ADV7180_REG_RES_CIR, 0xa8); |
| 1066 | adv7180_write(state, ADV7180_REG_CLAMP_ADJ, 0x90); |
| 1067 | adv7180_write(state, ADV7180_REG_DIFF_MODE, 0xb0); |
| 1068 | adv7180_write(state, ADV7180_REG_AGC_ADJ1, 0x08); |
| 1069 | adv7180_write(state, ADV7180_REG_AGC_ADJ2, 0xa0); |
Lars-Peter Clausen | c5ef8f8 | 2015-01-23 12:52:29 -0300 | [diff] [blame] | 1070 | } else { |
Steve Longerbeam | ce5d629 | 2016-07-19 21:03:30 -0300 | [diff] [blame] | 1071 | adv7180_write(state, ADV7180_REG_RES_CIR, 0xf0); |
| 1072 | adv7180_write(state, ADV7180_REG_CLAMP_ADJ, 0xd0); |
| 1073 | adv7180_write(state, ADV7180_REG_DIFF_MODE, 0x10); |
| 1074 | adv7180_write(state, ADV7180_REG_AGC_ADJ1, 0x9c); |
| 1075 | adv7180_write(state, ADV7180_REG_AGC_ADJ2, 0x00); |
Lars-Peter Clausen | c5ef8f8 | 2015-01-23 12:52:29 -0300 | [diff] [blame] | 1076 | } |
| 1077 | |
| 1078 | return 0; |
| 1079 | } |
| 1080 | |
Lars-Peter Clausen | f5dde49 | 2015-01-23 12:52:28 -0300 | [diff] [blame] | 1081 | static const struct adv7180_chip_info adv7180_info = { |
| 1082 | .flags = ADV7180_FLAG_RESET_POWERED, |
| 1083 | /* We cannot discriminate between LQFP and 40-pin LFCSP, so accept |
| 1084 | * all inputs and let the card driver take care of validation |
| 1085 | */ |
| 1086 | .valid_input_mask = BIT(ADV7180_INPUT_CVBS_AIN1) | |
| 1087 | BIT(ADV7180_INPUT_CVBS_AIN2) | |
| 1088 | BIT(ADV7180_INPUT_CVBS_AIN3) | |
| 1089 | BIT(ADV7180_INPUT_CVBS_AIN4) | |
| 1090 | BIT(ADV7180_INPUT_CVBS_AIN5) | |
| 1091 | BIT(ADV7180_INPUT_CVBS_AIN6) | |
| 1092 | BIT(ADV7180_INPUT_SVIDEO_AIN1_AIN2) | |
| 1093 | BIT(ADV7180_INPUT_SVIDEO_AIN3_AIN4) | |
| 1094 | BIT(ADV7180_INPUT_SVIDEO_AIN5_AIN6) | |
| 1095 | BIT(ADV7180_INPUT_YPRPB_AIN1_AIN2_AIN3) | |
| 1096 | BIT(ADV7180_INPUT_YPRPB_AIN4_AIN5_AIN6), |
| 1097 | .init = adv7180_init, |
| 1098 | .set_std = adv7180_set_std, |
| 1099 | .select_input = adv7180_select_input, |
| 1100 | }; |
| 1101 | |
Lars-Peter Clausen | c5ef8f8 | 2015-01-23 12:52:29 -0300 | [diff] [blame] | 1102 | static const struct adv7180_chip_info adv7182_info = { |
| 1103 | .valid_input_mask = BIT(ADV7182_INPUT_CVBS_AIN1) | |
| 1104 | BIT(ADV7182_INPUT_CVBS_AIN2) | |
| 1105 | BIT(ADV7182_INPUT_CVBS_AIN3) | |
| 1106 | BIT(ADV7182_INPUT_CVBS_AIN4) | |
| 1107 | BIT(ADV7182_INPUT_SVIDEO_AIN1_AIN2) | |
| 1108 | BIT(ADV7182_INPUT_SVIDEO_AIN3_AIN4) | |
| 1109 | BIT(ADV7182_INPUT_YPRPB_AIN1_AIN2_AIN3) | |
| 1110 | BIT(ADV7182_INPUT_DIFF_CVBS_AIN1_AIN2) | |
| 1111 | BIT(ADV7182_INPUT_DIFF_CVBS_AIN3_AIN4), |
| 1112 | .init = adv7182_init, |
| 1113 | .set_std = adv7182_set_std, |
| 1114 | .select_input = adv7182_select_input, |
| 1115 | }; |
| 1116 | |
Lars-Peter Clausen | bf7dcb8 | 2015-01-23 12:52:30 -0300 | [diff] [blame] | 1117 | static const struct adv7180_chip_info adv7280_info = { |
Lars-Peter Clausen | 851a54e | 2015-01-23 12:52:32 -0300 | [diff] [blame] | 1118 | .flags = ADV7180_FLAG_V2 | ADV7180_FLAG_I2P, |
Lars-Peter Clausen | bf7dcb8 | 2015-01-23 12:52:30 -0300 | [diff] [blame] | 1119 | .valid_input_mask = BIT(ADV7182_INPUT_CVBS_AIN1) | |
| 1120 | BIT(ADV7182_INPUT_CVBS_AIN2) | |
| 1121 | BIT(ADV7182_INPUT_CVBS_AIN3) | |
| 1122 | BIT(ADV7182_INPUT_CVBS_AIN4) | |
| 1123 | BIT(ADV7182_INPUT_SVIDEO_AIN1_AIN2) | |
| 1124 | BIT(ADV7182_INPUT_SVIDEO_AIN3_AIN4) | |
| 1125 | BIT(ADV7182_INPUT_YPRPB_AIN1_AIN2_AIN3), |
| 1126 | .init = adv7182_init, |
| 1127 | .set_std = adv7182_set_std, |
| 1128 | .select_input = adv7182_select_input, |
| 1129 | }; |
| 1130 | |
Lars-Peter Clausen | b37135e | 2015-01-23 12:52:31 -0300 | [diff] [blame] | 1131 | static const struct adv7180_chip_info adv7280_m_info = { |
Lars-Peter Clausen | 851a54e | 2015-01-23 12:52:32 -0300 | [diff] [blame] | 1132 | .flags = ADV7180_FLAG_V2 | ADV7180_FLAG_MIPI_CSI2 | ADV7180_FLAG_I2P, |
Lars-Peter Clausen | b37135e | 2015-01-23 12:52:31 -0300 | [diff] [blame] | 1133 | .valid_input_mask = BIT(ADV7182_INPUT_CVBS_AIN1) | |
| 1134 | BIT(ADV7182_INPUT_CVBS_AIN2) | |
| 1135 | BIT(ADV7182_INPUT_CVBS_AIN3) | |
| 1136 | BIT(ADV7182_INPUT_CVBS_AIN4) | |
| 1137 | BIT(ADV7182_INPUT_CVBS_AIN5) | |
| 1138 | BIT(ADV7182_INPUT_CVBS_AIN6) | |
| 1139 | BIT(ADV7182_INPUT_CVBS_AIN7) | |
| 1140 | BIT(ADV7182_INPUT_CVBS_AIN8) | |
| 1141 | BIT(ADV7182_INPUT_SVIDEO_AIN1_AIN2) | |
| 1142 | BIT(ADV7182_INPUT_SVIDEO_AIN3_AIN4) | |
| 1143 | BIT(ADV7182_INPUT_SVIDEO_AIN5_AIN6) | |
| 1144 | BIT(ADV7182_INPUT_SVIDEO_AIN7_AIN8) | |
| 1145 | BIT(ADV7182_INPUT_YPRPB_AIN1_AIN2_AIN3) | |
| 1146 | BIT(ADV7182_INPUT_YPRPB_AIN4_AIN5_AIN6), |
| 1147 | .init = adv7182_init, |
| 1148 | .set_std = adv7182_set_std, |
| 1149 | .select_input = adv7182_select_input, |
| 1150 | }; |
| 1151 | |
Lars-Peter Clausen | bf7dcb8 | 2015-01-23 12:52:30 -0300 | [diff] [blame] | 1152 | static const struct adv7180_chip_info adv7281_info = { |
Lars-Peter Clausen | b37135e | 2015-01-23 12:52:31 -0300 | [diff] [blame] | 1153 | .flags = ADV7180_FLAG_V2 | ADV7180_FLAG_MIPI_CSI2, |
Lars-Peter Clausen | bf7dcb8 | 2015-01-23 12:52:30 -0300 | [diff] [blame] | 1154 | .valid_input_mask = BIT(ADV7182_INPUT_CVBS_AIN1) | |
| 1155 | BIT(ADV7182_INPUT_CVBS_AIN2) | |
| 1156 | BIT(ADV7182_INPUT_CVBS_AIN7) | |
| 1157 | BIT(ADV7182_INPUT_CVBS_AIN8) | |
| 1158 | BIT(ADV7182_INPUT_SVIDEO_AIN1_AIN2) | |
| 1159 | BIT(ADV7182_INPUT_SVIDEO_AIN7_AIN8) | |
| 1160 | BIT(ADV7182_INPUT_DIFF_CVBS_AIN1_AIN2) | |
| 1161 | BIT(ADV7182_INPUT_DIFF_CVBS_AIN7_AIN8), |
| 1162 | .init = adv7182_init, |
| 1163 | .set_std = adv7182_set_std, |
| 1164 | .select_input = adv7182_select_input, |
| 1165 | }; |
| 1166 | |
Lars-Peter Clausen | b37135e | 2015-01-23 12:52:31 -0300 | [diff] [blame] | 1167 | static const struct adv7180_chip_info adv7281_m_info = { |
| 1168 | .flags = ADV7180_FLAG_V2 | ADV7180_FLAG_MIPI_CSI2, |
| 1169 | .valid_input_mask = BIT(ADV7182_INPUT_CVBS_AIN1) | |
| 1170 | BIT(ADV7182_INPUT_CVBS_AIN2) | |
| 1171 | BIT(ADV7182_INPUT_CVBS_AIN3) | |
| 1172 | BIT(ADV7182_INPUT_CVBS_AIN4) | |
| 1173 | BIT(ADV7182_INPUT_CVBS_AIN7) | |
| 1174 | BIT(ADV7182_INPUT_CVBS_AIN8) | |
| 1175 | BIT(ADV7182_INPUT_SVIDEO_AIN1_AIN2) | |
| 1176 | BIT(ADV7182_INPUT_SVIDEO_AIN3_AIN4) | |
| 1177 | BIT(ADV7182_INPUT_SVIDEO_AIN7_AIN8) | |
| 1178 | BIT(ADV7182_INPUT_YPRPB_AIN1_AIN2_AIN3) | |
| 1179 | BIT(ADV7182_INPUT_DIFF_CVBS_AIN1_AIN2) | |
| 1180 | BIT(ADV7182_INPUT_DIFF_CVBS_AIN3_AIN4) | |
| 1181 | BIT(ADV7182_INPUT_DIFF_CVBS_AIN7_AIN8), |
| 1182 | .init = adv7182_init, |
| 1183 | .set_std = adv7182_set_std, |
| 1184 | .select_input = adv7182_select_input, |
| 1185 | }; |
| 1186 | |
| 1187 | static const struct adv7180_chip_info adv7281_ma_info = { |
| 1188 | .flags = ADV7180_FLAG_V2 | ADV7180_FLAG_MIPI_CSI2, |
| 1189 | .valid_input_mask = BIT(ADV7182_INPUT_CVBS_AIN1) | |
| 1190 | BIT(ADV7182_INPUT_CVBS_AIN2) | |
| 1191 | BIT(ADV7182_INPUT_CVBS_AIN3) | |
| 1192 | BIT(ADV7182_INPUT_CVBS_AIN4) | |
| 1193 | BIT(ADV7182_INPUT_CVBS_AIN5) | |
| 1194 | BIT(ADV7182_INPUT_CVBS_AIN6) | |
| 1195 | BIT(ADV7182_INPUT_CVBS_AIN7) | |
| 1196 | BIT(ADV7182_INPUT_CVBS_AIN8) | |
| 1197 | BIT(ADV7182_INPUT_SVIDEO_AIN1_AIN2) | |
| 1198 | BIT(ADV7182_INPUT_SVIDEO_AIN3_AIN4) | |
| 1199 | BIT(ADV7182_INPUT_SVIDEO_AIN5_AIN6) | |
| 1200 | BIT(ADV7182_INPUT_SVIDEO_AIN7_AIN8) | |
| 1201 | BIT(ADV7182_INPUT_YPRPB_AIN1_AIN2_AIN3) | |
| 1202 | BIT(ADV7182_INPUT_YPRPB_AIN4_AIN5_AIN6) | |
| 1203 | BIT(ADV7182_INPUT_DIFF_CVBS_AIN1_AIN2) | |
| 1204 | BIT(ADV7182_INPUT_DIFF_CVBS_AIN3_AIN4) | |
| 1205 | BIT(ADV7182_INPUT_DIFF_CVBS_AIN5_AIN6) | |
| 1206 | BIT(ADV7182_INPUT_DIFF_CVBS_AIN7_AIN8), |
| 1207 | .init = adv7182_init, |
| 1208 | .set_std = adv7182_set_std, |
| 1209 | .select_input = adv7182_select_input, |
| 1210 | }; |
| 1211 | |
Lars-Peter Clausen | 851a54e | 2015-01-23 12:52:32 -0300 | [diff] [blame] | 1212 | static const struct adv7180_chip_info adv7282_info = { |
| 1213 | .flags = ADV7180_FLAG_V2 | ADV7180_FLAG_I2P, |
| 1214 | .valid_input_mask = BIT(ADV7182_INPUT_CVBS_AIN1) | |
| 1215 | BIT(ADV7182_INPUT_CVBS_AIN2) | |
| 1216 | BIT(ADV7182_INPUT_CVBS_AIN7) | |
| 1217 | BIT(ADV7182_INPUT_CVBS_AIN8) | |
| 1218 | BIT(ADV7182_INPUT_SVIDEO_AIN1_AIN2) | |
| 1219 | BIT(ADV7182_INPUT_SVIDEO_AIN7_AIN8) | |
| 1220 | BIT(ADV7182_INPUT_DIFF_CVBS_AIN1_AIN2) | |
| 1221 | BIT(ADV7182_INPUT_DIFF_CVBS_AIN7_AIN8), |
| 1222 | .init = adv7182_init, |
| 1223 | .set_std = adv7182_set_std, |
| 1224 | .select_input = adv7182_select_input, |
| 1225 | }; |
| 1226 | |
| 1227 | static const struct adv7180_chip_info adv7282_m_info = { |
| 1228 | .flags = ADV7180_FLAG_V2 | ADV7180_FLAG_MIPI_CSI2 | ADV7180_FLAG_I2P, |
| 1229 | .valid_input_mask = BIT(ADV7182_INPUT_CVBS_AIN1) | |
| 1230 | BIT(ADV7182_INPUT_CVBS_AIN2) | |
| 1231 | BIT(ADV7182_INPUT_CVBS_AIN3) | |
| 1232 | BIT(ADV7182_INPUT_CVBS_AIN4) | |
| 1233 | BIT(ADV7182_INPUT_CVBS_AIN7) | |
| 1234 | BIT(ADV7182_INPUT_CVBS_AIN8) | |
| 1235 | BIT(ADV7182_INPUT_SVIDEO_AIN1_AIN2) | |
| 1236 | BIT(ADV7182_INPUT_SVIDEO_AIN3_AIN4) | |
| 1237 | BIT(ADV7182_INPUT_SVIDEO_AIN7_AIN8) | |
| 1238 | BIT(ADV7182_INPUT_DIFF_CVBS_AIN1_AIN2) | |
| 1239 | BIT(ADV7182_INPUT_DIFF_CVBS_AIN3_AIN4) | |
| 1240 | BIT(ADV7182_INPUT_DIFF_CVBS_AIN7_AIN8), |
| 1241 | .init = adv7182_init, |
| 1242 | .set_std = adv7182_set_std, |
| 1243 | .select_input = adv7182_select_input, |
| 1244 | }; |
| 1245 | |
Lars-Peter Clausen | 3999e5d | 2015-01-23 12:52:24 -0300 | [diff] [blame] | 1246 | static int init_device(struct adv7180_state *state) |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 1247 | { |
| 1248 | int ret; |
| 1249 | |
Lars-Peter Clausen | 3999e5d | 2015-01-23 12:52:24 -0300 | [diff] [blame] | 1250 | mutex_lock(&state->mutex); |
| 1251 | |
Steve Longerbeam | 65d9e14 | 2016-07-19 21:03:32 -0300 | [diff] [blame] | 1252 | adv7180_set_power_pin(state, true); |
| 1253 | |
Lars-Peter Clausen | c18818e | 2015-01-23 12:52:25 -0300 | [diff] [blame] | 1254 | adv7180_write(state, ADV7180_REG_PWR_MAN, ADV7180_PWR_MAN_RES); |
Ulrich Hecht | 16dfe72 | 2015-11-10 11:39:00 -0200 | [diff] [blame] | 1255 | usleep_range(5000, 10000); |
Lars-Peter Clausen | c18818e | 2015-01-23 12:52:25 -0300 | [diff] [blame] | 1256 | |
Lars-Peter Clausen | f5dde49 | 2015-01-23 12:52:28 -0300 | [diff] [blame] | 1257 | ret = state->chip_info->init(state); |
Lars-Peter Clausen | 3e35e33 | 2015-01-23 12:52:27 -0300 | [diff] [blame] | 1258 | if (ret) |
| 1259 | goto out_unlock; |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 1260 | |
Lars-Peter Clausen | f5dde49 | 2015-01-23 12:52:28 -0300 | [diff] [blame] | 1261 | ret = adv7180_program_std(state); |
| 1262 | if (ret) |
Lars-Peter Clausen | 3999e5d | 2015-01-23 12:52:24 -0300 | [diff] [blame] | 1263 | goto out_unlock; |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 1264 | |
Lars-Peter Clausen | 851a54e | 2015-01-23 12:52:32 -0300 | [diff] [blame] | 1265 | adv7180_set_field_mode(state); |
| 1266 | |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 1267 | /* register for interrupts */ |
| 1268 | if (state->irq > 0) { |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 1269 | /* config the Interrupt pin to be active low */ |
Lars-Peter Clausen | 3999e5d | 2015-01-23 12:52:24 -0300 | [diff] [blame] | 1270 | ret = adv7180_write(state, ADV7180_REG_ICONF1, |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 1271 | ADV7180_ICONF1_ACTIVE_LOW | |
| 1272 | ADV7180_ICONF1_PSYNC_ONLY); |
| 1273 | if (ret < 0) |
Lars-Peter Clausen | 3999e5d | 2015-01-23 12:52:24 -0300 | [diff] [blame] | 1274 | goto out_unlock; |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 1275 | |
Lars-Peter Clausen | 3999e5d | 2015-01-23 12:52:24 -0300 | [diff] [blame] | 1276 | ret = adv7180_write(state, ADV7180_REG_IMR1, 0); |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 1277 | if (ret < 0) |
Lars-Peter Clausen | 3999e5d | 2015-01-23 12:52:24 -0300 | [diff] [blame] | 1278 | goto out_unlock; |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 1279 | |
Lars-Peter Clausen | 3999e5d | 2015-01-23 12:52:24 -0300 | [diff] [blame] | 1280 | ret = adv7180_write(state, ADV7180_REG_IMR2, 0); |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 1281 | if (ret < 0) |
Lars-Peter Clausen | 3999e5d | 2015-01-23 12:52:24 -0300 | [diff] [blame] | 1282 | goto out_unlock; |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 1283 | |
| 1284 | /* enable AD change interrupts interrupts */ |
Lars-Peter Clausen | 3999e5d | 2015-01-23 12:52:24 -0300 | [diff] [blame] | 1285 | ret = adv7180_write(state, ADV7180_REG_IMR3, |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 1286 | ADV7180_IRQ3_AD_CHANGE); |
| 1287 | if (ret < 0) |
Lars-Peter Clausen | 3999e5d | 2015-01-23 12:52:24 -0300 | [diff] [blame] | 1288 | goto out_unlock; |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 1289 | |
Lars-Peter Clausen | 3999e5d | 2015-01-23 12:52:24 -0300 | [diff] [blame] | 1290 | ret = adv7180_write(state, ADV7180_REG_IMR4, 0); |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 1291 | if (ret < 0) |
Lars-Peter Clausen | 3999e5d | 2015-01-23 12:52:24 -0300 | [diff] [blame] | 1292 | goto out_unlock; |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 1293 | } |
| 1294 | |
Lars-Peter Clausen | 3999e5d | 2015-01-23 12:52:24 -0300 | [diff] [blame] | 1295 | out_unlock: |
| 1296 | mutex_unlock(&state->mutex); |
Alexey Khoroshilov | df065b3 | 2014-03-14 18:04:03 -0300 | [diff] [blame] | 1297 | |
Alexey Khoroshilov | df065b3 | 2014-03-14 18:04:03 -0300 | [diff] [blame] | 1298 | return ret; |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 1299 | } |
Richard Röjfors | 6789cb5 | 2009-09-18 21:17:20 -0300 | [diff] [blame] | 1300 | |
Greg Kroah-Hartman | 4c62e97 | 2012-12-21 13:17:53 -0800 | [diff] [blame] | 1301 | static int adv7180_probe(struct i2c_client *client, |
| 1302 | const struct i2c_device_id *id) |
Richard Röjfors | 6789cb5 | 2009-09-18 21:17:20 -0300 | [diff] [blame] | 1303 | { |
| 1304 | struct adv7180_state *state; |
| 1305 | struct v4l2_subdev *sd; |
| 1306 | int ret; |
| 1307 | |
| 1308 | /* Check if the adapter supports the needed features */ |
| 1309 | if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
| 1310 | return -EIO; |
| 1311 | |
| 1312 | v4l_info(client, "chip found @ 0x%02x (%s)\n", |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 1313 | client->addr, client->adapter->name); |
Richard Röjfors | 6789cb5 | 2009-09-18 21:17:20 -0300 | [diff] [blame] | 1314 | |
Laurent Pinchart | c02b211 | 2013-05-02 08:29:43 -0300 | [diff] [blame] | 1315 | state = devm_kzalloc(&client->dev, sizeof(*state), GFP_KERNEL); |
Fabio Estevam | 7657e064 | 2014-12-16 13:49:07 -0300 | [diff] [blame] | 1316 | if (state == NULL) |
| 1317 | return -ENOMEM; |
Richard Röjfors | 42752f7 | 2009-09-22 06:07:06 -0300 | [diff] [blame] | 1318 | |
Lars-Peter Clausen | 3999e5d | 2015-01-23 12:52:24 -0300 | [diff] [blame] | 1319 | state->client = client; |
Niklas Söderlund | 6457b62 | 2018-07-26 06:27:15 -0400 | [diff] [blame] | 1320 | state->field = V4L2_FIELD_ALTERNATE; |
Lars-Peter Clausen | f5dde49 | 2015-01-23 12:52:28 -0300 | [diff] [blame] | 1321 | state->chip_info = (struct adv7180_chip_info *)id->driver_data; |
Lars-Peter Clausen | 3999e5d | 2015-01-23 12:52:24 -0300 | [diff] [blame] | 1322 | |
Steve Longerbeam | 65d9e14 | 2016-07-19 21:03:32 -0300 | [diff] [blame] | 1323 | state->pwdn_gpio = devm_gpiod_get_optional(&client->dev, "powerdown", |
| 1324 | GPIOD_OUT_HIGH); |
| 1325 | if (IS_ERR(state->pwdn_gpio)) { |
| 1326 | ret = PTR_ERR(state->pwdn_gpio); |
| 1327 | v4l_err(client, "request for power pin failed: %d\n", ret); |
| 1328 | return ret; |
| 1329 | } |
| 1330 | |
Lars-Peter Clausen | b37135e | 2015-01-23 12:52:31 -0300 | [diff] [blame] | 1331 | if (state->chip_info->flags & ADV7180_FLAG_MIPI_CSI2) { |
Wolfram Sang | 31b9754 | 2019-07-22 14:26:00 -0300 | [diff] [blame^] | 1332 | state->csi_client = i2c_new_dummy_device(client->adapter, |
Lars-Peter Clausen | b37135e | 2015-01-23 12:52:31 -0300 | [diff] [blame] | 1333 | ADV7180_DEFAULT_CSI_I2C_ADDR); |
Wolfram Sang | 31b9754 | 2019-07-22 14:26:00 -0300 | [diff] [blame^] | 1334 | if (IS_ERR(state->csi_client)) |
| 1335 | return PTR_ERR(state->csi_client); |
Lars-Peter Clausen | b37135e | 2015-01-23 12:52:31 -0300 | [diff] [blame] | 1336 | } |
| 1337 | |
Lars-Peter Clausen | 851a54e | 2015-01-23 12:52:32 -0300 | [diff] [blame] | 1338 | if (state->chip_info->flags & ADV7180_FLAG_I2P) { |
Wolfram Sang | 31b9754 | 2019-07-22 14:26:00 -0300 | [diff] [blame^] | 1339 | state->vpp_client = i2c_new_dummy_device(client->adapter, |
Lars-Peter Clausen | 851a54e | 2015-01-23 12:52:32 -0300 | [diff] [blame] | 1340 | ADV7180_DEFAULT_VPP_I2C_ADDR); |
Wolfram Sang | 31b9754 | 2019-07-22 14:26:00 -0300 | [diff] [blame^] | 1341 | if (IS_ERR(state->vpp_client)) { |
| 1342 | ret = PTR_ERR(state->vpp_client); |
Lars-Peter Clausen | 851a54e | 2015-01-23 12:52:32 -0300 | [diff] [blame] | 1343 | goto err_unregister_csi_client; |
| 1344 | } |
| 1345 | } |
| 1346 | |
Richard Röjfors | 42752f7 | 2009-09-22 06:07:06 -0300 | [diff] [blame] | 1347 | state->irq = client->irq; |
Richard Röjfors | 42752f7 | 2009-09-22 06:07:06 -0300 | [diff] [blame] | 1348 | mutex_init(&state->mutex); |
Hans Verkuil | 937feee | 2016-04-22 10:03:37 -0300 | [diff] [blame] | 1349 | state->curr_norm = V4L2_STD_NTSC; |
Lars-Peter Clausen | f5dde49 | 2015-01-23 12:52:28 -0300 | [diff] [blame] | 1350 | if (state->chip_info->flags & ADV7180_FLAG_RESET_POWERED) |
| 1351 | state->powered = true; |
| 1352 | else |
| 1353 | state->powered = false; |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 1354 | state->input = 0; |
Richard Röjfors | 6789cb5 | 2009-09-18 21:17:20 -0300 | [diff] [blame] | 1355 | sd = &state->sd; |
| 1356 | v4l2_i2c_subdev_init(sd, client, &adv7180_ops); |
Akinobu Mita | 5cc72c4 | 2017-10-19 12:31:20 -0400 | [diff] [blame] | 1357 | sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE | V4L2_SUBDEV_FL_HAS_EVENTS; |
Richard Röjfors | 6789cb5 | 2009-09-18 21:17:20 -0300 | [diff] [blame] | 1358 | |
Federico Vaga | c9fbedd | 2012-07-11 11:29:33 -0300 | [diff] [blame] | 1359 | ret = adv7180_init_controls(state); |
| 1360 | if (ret) |
Lars-Peter Clausen | 851a54e | 2015-01-23 12:52:32 -0300 | [diff] [blame] | 1361 | goto err_unregister_vpp_client; |
Lars-Peter Clausen | d5d51a8 | 2015-01-23 12:52:26 -0300 | [diff] [blame] | 1362 | |
| 1363 | state->pad.flags = MEDIA_PAD_FL_SOURCE; |
Hans Verkuil | ca0fa5f | 2018-06-18 05:09:45 -0400 | [diff] [blame] | 1364 | sd->entity.function = MEDIA_ENT_F_ATV_DECODER; |
Mauro Carvalho Chehab | ab22e77 | 2015-12-11 07:44:40 -0200 | [diff] [blame] | 1365 | ret = media_entity_pads_init(&sd->entity, 1, &state->pad); |
Federico Vaga | c9fbedd | 2012-07-11 11:29:33 -0300 | [diff] [blame] | 1366 | if (ret) |
| 1367 | goto err_free_ctrl; |
Lars-Peter Clausen | fa5b794 | 2014-03-07 13:14:32 -0300 | [diff] [blame] | 1368 | |
Lars-Peter Clausen | d5d51a8 | 2015-01-23 12:52:26 -0300 | [diff] [blame] | 1369 | ret = init_device(state); |
| 1370 | if (ret) |
| 1371 | goto err_media_entity_cleanup; |
| 1372 | |
Lars-Peter Clausen | fa5721d | 2015-01-23 12:52:20 -0300 | [diff] [blame] | 1373 | if (state->irq) { |
| 1374 | ret = request_threaded_irq(client->irq, NULL, adv7180_irq, |
Lars-Peter Clausen | f3e991d | 2015-01-23 12:52:21 -0300 | [diff] [blame] | 1375 | IRQF_ONESHOT | IRQF_TRIGGER_FALLING, |
| 1376 | KBUILD_MODNAME, state); |
Lars-Peter Clausen | fa5721d | 2015-01-23 12:52:20 -0300 | [diff] [blame] | 1377 | if (ret) |
Lars-Peter Clausen | d5d51a8 | 2015-01-23 12:52:26 -0300 | [diff] [blame] | 1378 | goto err_media_entity_cleanup; |
Lars-Peter Clausen | fa5721d | 2015-01-23 12:52:20 -0300 | [diff] [blame] | 1379 | } |
| 1380 | |
Lars-Peter Clausen | fa5b794 | 2014-03-07 13:14:32 -0300 | [diff] [blame] | 1381 | ret = v4l2_async_register_subdev(sd); |
| 1382 | if (ret) |
| 1383 | goto err_free_irq; |
| 1384 | |
Richard Röjfors | 6789cb5 | 2009-09-18 21:17:20 -0300 | [diff] [blame] | 1385 | return 0; |
Richard Röjfors | 42752f7 | 2009-09-22 06:07:06 -0300 | [diff] [blame] | 1386 | |
Lars-Peter Clausen | fa5b794 | 2014-03-07 13:14:32 -0300 | [diff] [blame] | 1387 | err_free_irq: |
| 1388 | if (state->irq > 0) |
| 1389 | free_irq(client->irq, state); |
Lars-Peter Clausen | d5d51a8 | 2015-01-23 12:52:26 -0300 | [diff] [blame] | 1390 | err_media_entity_cleanup: |
| 1391 | media_entity_cleanup(&sd->entity); |
Federico Vaga | c9fbedd | 2012-07-11 11:29:33 -0300 | [diff] [blame] | 1392 | err_free_ctrl: |
| 1393 | adv7180_exit_controls(state); |
Lars-Peter Clausen | 851a54e | 2015-01-23 12:52:32 -0300 | [diff] [blame] | 1394 | err_unregister_vpp_client: |
Andy Shevchenko | 297aca1 | 2017-10-31 10:21:48 -0400 | [diff] [blame] | 1395 | i2c_unregister_device(state->vpp_client); |
Lars-Peter Clausen | b37135e | 2015-01-23 12:52:31 -0300 | [diff] [blame] | 1396 | err_unregister_csi_client: |
Andy Shevchenko | 297aca1 | 2017-10-31 10:21:48 -0400 | [diff] [blame] | 1397 | i2c_unregister_device(state->csi_client); |
Lars-Peter Clausen | 297a0ae | 2014-03-07 13:14:27 -0300 | [diff] [blame] | 1398 | mutex_destroy(&state->mutex); |
Richard Röjfors | 42752f7 | 2009-09-22 06:07:06 -0300 | [diff] [blame] | 1399 | return ret; |
Richard Röjfors | 6789cb5 | 2009-09-18 21:17:20 -0300 | [diff] [blame] | 1400 | } |
| 1401 | |
Greg Kroah-Hartman | 4c62e97 | 2012-12-21 13:17:53 -0800 | [diff] [blame] | 1402 | static int adv7180_remove(struct i2c_client *client) |
Richard Röjfors | 6789cb5 | 2009-09-18 21:17:20 -0300 | [diff] [blame] | 1403 | { |
| 1404 | struct v4l2_subdev *sd = i2c_get_clientdata(client); |
Richard Röjfors | 42752f7 | 2009-09-22 06:07:06 -0300 | [diff] [blame] | 1405 | struct adv7180_state *state = to_state(sd); |
Richard Röjfors | 6789cb5 | 2009-09-18 21:17:20 -0300 | [diff] [blame] | 1406 | |
Lars-Peter Clausen | fa5b794 | 2014-03-07 13:14:32 -0300 | [diff] [blame] | 1407 | v4l2_async_unregister_subdev(sd); |
| 1408 | |
Lars-Peter Clausen | 0c25534 | 2014-03-07 13:14:31 -0300 | [diff] [blame] | 1409 | if (state->irq > 0) |
Richard Röjfors | 42752f7 | 2009-09-22 06:07:06 -0300 | [diff] [blame] | 1410 | free_irq(client->irq, state); |
Richard Röjfors | 42752f7 | 2009-09-22 06:07:06 -0300 | [diff] [blame] | 1411 | |
Lars-Peter Clausen | d5d51a8 | 2015-01-23 12:52:26 -0300 | [diff] [blame] | 1412 | media_entity_cleanup(&sd->entity); |
Lars-Peter Clausen | b13f4af | 2014-03-07 13:14:28 -0300 | [diff] [blame] | 1413 | adv7180_exit_controls(state); |
Lars-Peter Clausen | b37135e | 2015-01-23 12:52:31 -0300 | [diff] [blame] | 1414 | |
Andy Shevchenko | 297aca1 | 2017-10-31 10:21:48 -0400 | [diff] [blame] | 1415 | i2c_unregister_device(state->vpp_client); |
| 1416 | i2c_unregister_device(state->csi_client); |
Lars-Peter Clausen | b37135e | 2015-01-23 12:52:31 -0300 | [diff] [blame] | 1417 | |
Steve Longerbeam | 65d9e14 | 2016-07-19 21:03:32 -0300 | [diff] [blame] | 1418 | adv7180_set_power_pin(state, false); |
| 1419 | |
Lars-Peter Clausen | 297a0ae | 2014-03-07 13:14:27 -0300 | [diff] [blame] | 1420 | mutex_destroy(&state->mutex); |
Lars-Peter Clausen | b37135e | 2015-01-23 12:52:31 -0300 | [diff] [blame] | 1421 | |
Richard Röjfors | 6789cb5 | 2009-09-18 21:17:20 -0300 | [diff] [blame] | 1422 | return 0; |
| 1423 | } |
| 1424 | |
| 1425 | static const struct i2c_device_id adv7180_id[] = { |
Lars-Peter Clausen | f5dde49 | 2015-01-23 12:52:28 -0300 | [diff] [blame] | 1426 | { "adv7180", (kernel_ulong_t)&adv7180_info }, |
Ulrich Hecht | 281ddc3 | 2017-07-03 04:43:33 -0400 | [diff] [blame] | 1427 | { "adv7180cp", (kernel_ulong_t)&adv7180_info }, |
| 1428 | { "adv7180st", (kernel_ulong_t)&adv7180_info }, |
Lars-Peter Clausen | c5ef8f8 | 2015-01-23 12:52:29 -0300 | [diff] [blame] | 1429 | { "adv7182", (kernel_ulong_t)&adv7182_info }, |
Lars-Peter Clausen | bf7dcb8 | 2015-01-23 12:52:30 -0300 | [diff] [blame] | 1430 | { "adv7280", (kernel_ulong_t)&adv7280_info }, |
Lars-Peter Clausen | b37135e | 2015-01-23 12:52:31 -0300 | [diff] [blame] | 1431 | { "adv7280-m", (kernel_ulong_t)&adv7280_m_info }, |
Lars-Peter Clausen | bf7dcb8 | 2015-01-23 12:52:30 -0300 | [diff] [blame] | 1432 | { "adv7281", (kernel_ulong_t)&adv7281_info }, |
Lars-Peter Clausen | b37135e | 2015-01-23 12:52:31 -0300 | [diff] [blame] | 1433 | { "adv7281-m", (kernel_ulong_t)&adv7281_m_info }, |
| 1434 | { "adv7281-ma", (kernel_ulong_t)&adv7281_ma_info }, |
Lars-Peter Clausen | 851a54e | 2015-01-23 12:52:32 -0300 | [diff] [blame] | 1435 | { "adv7282", (kernel_ulong_t)&adv7282_info }, |
| 1436 | { "adv7282-m", (kernel_ulong_t)&adv7282_m_info }, |
Richard Röjfors | 6789cb5 | 2009-09-18 21:17:20 -0300 | [diff] [blame] | 1437 | {}, |
| 1438 | }; |
Lars-Peter Clausen | f5dde49 | 2015-01-23 12:52:28 -0300 | [diff] [blame] | 1439 | MODULE_DEVICE_TABLE(i2c, adv7180_id); |
Richard Röjfors | 6789cb5 | 2009-09-18 21:17:20 -0300 | [diff] [blame] | 1440 | |
Lars-Peter Clausen | cc1088d | 2013-04-13 05:25:59 -0300 | [diff] [blame] | 1441 | #ifdef CONFIG_PM_SLEEP |
| 1442 | static int adv7180_suspend(struct device *dev) |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 1443 | { |
Lars-Peter Clausen | cc1088d | 2013-04-13 05:25:59 -0300 | [diff] [blame] | 1444 | struct i2c_client *client = to_i2c_client(dev); |
Lars-Peter Clausen | e246c33 | 2014-03-10 14:05:39 -0300 | [diff] [blame] | 1445 | struct v4l2_subdev *sd = i2c_get_clientdata(client); |
| 1446 | struct adv7180_state *state = to_state(sd); |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 1447 | |
Lars-Peter Clausen | 3999e5d | 2015-01-23 12:52:24 -0300 | [diff] [blame] | 1448 | return adv7180_set_power(state, false); |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 1449 | } |
| 1450 | |
Lars-Peter Clausen | cc1088d | 2013-04-13 05:25:59 -0300 | [diff] [blame] | 1451 | static int adv7180_resume(struct device *dev) |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 1452 | { |
Lars-Peter Clausen | cc1088d | 2013-04-13 05:25:59 -0300 | [diff] [blame] | 1453 | struct i2c_client *client = to_i2c_client(dev); |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 1454 | struct v4l2_subdev *sd = i2c_get_clientdata(client); |
| 1455 | struct adv7180_state *state = to_state(sd); |
| 1456 | int ret; |
| 1457 | |
Lars-Peter Clausen | 3999e5d | 2015-01-23 12:52:24 -0300 | [diff] [blame] | 1458 | ret = init_device(state); |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 1459 | if (ret < 0) |
| 1460 | return ret; |
Lars-Peter Clausen | c18818e | 2015-01-23 12:52:25 -0300 | [diff] [blame] | 1461 | |
| 1462 | ret = adv7180_set_power(state, state->powered); |
| 1463 | if (ret) |
| 1464 | return ret; |
| 1465 | |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 1466 | return 0; |
| 1467 | } |
Lars-Peter Clausen | cc1088d | 2013-04-13 05:25:59 -0300 | [diff] [blame] | 1468 | |
| 1469 | static SIMPLE_DEV_PM_OPS(adv7180_pm_ops, adv7180_suspend, adv7180_resume); |
| 1470 | #define ADV7180_PM_OPS (&adv7180_pm_ops) |
| 1471 | |
| 1472 | #else |
| 1473 | #define ADV7180_PM_OPS NULL |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 1474 | #endif |
| 1475 | |
Ben Dooks | 250121d | 2015-06-03 10:59:50 -0300 | [diff] [blame] | 1476 | #ifdef CONFIG_OF |
| 1477 | static const struct of_device_id adv7180_of_id[] = { |
| 1478 | { .compatible = "adi,adv7180", }, |
Ulrich Hecht | ce1ec5c | 2017-05-19 10:07:02 -0300 | [diff] [blame] | 1479 | { .compatible = "adi,adv7180cp", }, |
| 1480 | { .compatible = "adi,adv7180st", }, |
Julian Scheel | bf14e74 | 2016-02-23 18:11:21 -0300 | [diff] [blame] | 1481 | { .compatible = "adi,adv7182", }, |
| 1482 | { .compatible = "adi,adv7280", }, |
| 1483 | { .compatible = "adi,adv7280-m", }, |
| 1484 | { .compatible = "adi,adv7281", }, |
| 1485 | { .compatible = "adi,adv7281-m", }, |
| 1486 | { .compatible = "adi,adv7281-ma", }, |
| 1487 | { .compatible = "adi,adv7282", }, |
| 1488 | { .compatible = "adi,adv7282-m", }, |
Ben Dooks | 250121d | 2015-06-03 10:59:50 -0300 | [diff] [blame] | 1489 | { }, |
| 1490 | }; |
| 1491 | |
| 1492 | MODULE_DEVICE_TABLE(of, adv7180_of_id); |
| 1493 | #endif |
| 1494 | |
Richard Röjfors | 6789cb5 | 2009-09-18 21:17:20 -0300 | [diff] [blame] | 1495 | static struct i2c_driver adv7180_driver = { |
| 1496 | .driver = { |
Federico Vaga | c9fbedd | 2012-07-11 11:29:33 -0300 | [diff] [blame] | 1497 | .name = KBUILD_MODNAME, |
Lars-Peter Clausen | cc1088d | 2013-04-13 05:25:59 -0300 | [diff] [blame] | 1498 | .pm = ADV7180_PM_OPS, |
Ben Dooks | 250121d | 2015-06-03 10:59:50 -0300 | [diff] [blame] | 1499 | .of_match_table = of_match_ptr(adv7180_of_id), |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 1500 | }, |
| 1501 | .probe = adv7180_probe, |
Greg Kroah-Hartman | 4c62e97 | 2012-12-21 13:17:53 -0800 | [diff] [blame] | 1502 | .remove = adv7180_remove, |
Federico Vaga | bca7ad1 | 2012-04-12 12:39:36 -0300 | [diff] [blame] | 1503 | .id_table = adv7180_id, |
Richard Röjfors | 6789cb5 | 2009-09-18 21:17:20 -0300 | [diff] [blame] | 1504 | }; |
| 1505 | |
Axel Lin | c6e8d86 | 2012-02-12 06:56:32 -0300 | [diff] [blame] | 1506 | module_i2c_driver(adv7180_driver); |
Richard Röjfors | 6789cb5 | 2009-09-18 21:17:20 -0300 | [diff] [blame] | 1507 | |
| 1508 | MODULE_DESCRIPTION("Analog Devices ADV7180 video decoder driver"); |
| 1509 | MODULE_AUTHOR("Mocean Laboratories"); |
| 1510 | MODULE_LICENSE("GPL v2"); |