Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1 | /* |
| 2 | * adv7604 - Analog Devices ADV7604 video decoder driver |
| 3 | * |
| 4 | * Copyright 2012 Cisco Systems, Inc. and/or its affiliates. All rights reserved. |
| 5 | * |
| 6 | * This program is free software; you may redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 9 | * |
| 10 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 11 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 12 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 13 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 14 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 15 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 16 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 17 | * SOFTWARE. |
| 18 | * |
| 19 | */ |
| 20 | |
| 21 | /* |
| 22 | * References (c = chapter, p = page): |
| 23 | * REF_01 - Analog devices, ADV7604, Register Settings Recommendations, |
| 24 | * Revision 2.5, June 2010 |
| 25 | * REF_02 - Analog devices, Register map documentation, Documentation of |
| 26 | * the register maps, Software manual, Rev. F, June 2010 |
| 27 | * REF_03 - Analog devices, ADV7604, Hardware Manual, Rev. F, August 2010 |
| 28 | */ |
| 29 | |
Laurent Pinchart | c72a53c | 2014-01-30 19:18:34 -0300 | [diff] [blame] | 30 | #include <linux/delay.h> |
Laurent Pinchart | e9d50e9 | 2014-01-30 18:37:08 -0300 | [diff] [blame] | 31 | #include <linux/gpio/consumer.h> |
Laurent Pinchart | c72a53c | 2014-01-30 19:18:34 -0300 | [diff] [blame] | 32 | #include <linux/i2c.h> |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 33 | #include <linux/kernel.h> |
| 34 | #include <linux/module.h> |
| 35 | #include <linux/slab.h> |
Laurent Pinchart | c72a53c | 2014-01-30 19:18:34 -0300 | [diff] [blame] | 36 | #include <linux/v4l2-dv-timings.h> |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 37 | #include <linux/videodev2.h> |
| 38 | #include <linux/workqueue.h> |
Laurent Pinchart | c72a53c | 2014-01-30 19:18:34 -0300 | [diff] [blame] | 39 | |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 40 | #include <media/adv7604.h> |
Laurent Pinchart | c72a53c | 2014-01-30 19:18:34 -0300 | [diff] [blame] | 41 | #include <media/v4l2-ctrls.h> |
| 42 | #include <media/v4l2-device.h> |
| 43 | #include <media/v4l2-dv-timings.h> |
Laurent Pinchart | 6fa8804 | 2014-02-04 20:23:16 -0300 | [diff] [blame] | 44 | #include <media/v4l2-of.h> |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 45 | |
| 46 | static int debug; |
| 47 | module_param(debug, int, 0644); |
| 48 | MODULE_PARM_DESC(debug, "debug level (0-2)"); |
| 49 | |
| 50 | MODULE_DESCRIPTION("Analog Devices ADV7604 video decoder driver"); |
| 51 | MODULE_AUTHOR("Hans Verkuil <hans.verkuil@cisco.com>"); |
| 52 | MODULE_AUTHOR("Mats Randgaard <mats.randgaard@cisco.com>"); |
| 53 | MODULE_LICENSE("GPL"); |
| 54 | |
| 55 | /* ADV7604 system clock frequency */ |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 56 | #define ADV76XX_FSC (28636360) |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 57 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 58 | #define ADV76XX_RGB_OUT (1 << 1) |
Laurent Pinchart | 539b33b | 2014-01-26 18:42:37 -0300 | [diff] [blame] | 59 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 60 | #define ADV76XX_OP_FORMAT_SEL_8BIT (0 << 0) |
Laurent Pinchart | 539b33b | 2014-01-26 18:42:37 -0300 | [diff] [blame] | 61 | #define ADV7604_OP_FORMAT_SEL_10BIT (1 << 0) |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 62 | #define ADV76XX_OP_FORMAT_SEL_12BIT (2 << 0) |
Laurent Pinchart | 539b33b | 2014-01-26 18:42:37 -0300 | [diff] [blame] | 63 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 64 | #define ADV76XX_OP_MODE_SEL_SDR_422 (0 << 5) |
Laurent Pinchart | 539b33b | 2014-01-26 18:42:37 -0300 | [diff] [blame] | 65 | #define ADV7604_OP_MODE_SEL_DDR_422 (1 << 5) |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 66 | #define ADV76XX_OP_MODE_SEL_SDR_444 (2 << 5) |
Laurent Pinchart | 539b33b | 2014-01-26 18:42:37 -0300 | [diff] [blame] | 67 | #define ADV7604_OP_MODE_SEL_DDR_444 (3 << 5) |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 68 | #define ADV76XX_OP_MODE_SEL_SDR_422_2X (4 << 5) |
Laurent Pinchart | 539b33b | 2014-01-26 18:42:37 -0300 | [diff] [blame] | 69 | #define ADV7604_OP_MODE_SEL_ADI_CM (5 << 5) |
| 70 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 71 | #define ADV76XX_OP_CH_SEL_GBR (0 << 5) |
| 72 | #define ADV76XX_OP_CH_SEL_GRB (1 << 5) |
| 73 | #define ADV76XX_OP_CH_SEL_BGR (2 << 5) |
| 74 | #define ADV76XX_OP_CH_SEL_RGB (3 << 5) |
| 75 | #define ADV76XX_OP_CH_SEL_BRG (4 << 5) |
| 76 | #define ADV76XX_OP_CH_SEL_RBG (5 << 5) |
Laurent Pinchart | 539b33b | 2014-01-26 18:42:37 -0300 | [diff] [blame] | 77 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 78 | #define ADV76XX_OP_SWAP_CB_CR (1 << 0) |
Laurent Pinchart | 539b33b | 2014-01-26 18:42:37 -0300 | [diff] [blame] | 79 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 80 | enum adv76xx_type { |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 81 | ADV7604, |
| 82 | ADV7611, |
| 83 | }; |
| 84 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 85 | struct adv76xx_reg_seq { |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 86 | unsigned int reg; |
| 87 | u8 val; |
| 88 | }; |
| 89 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 90 | struct adv76xx_format_info { |
Boris BREZILLON | f5fe58f | 2014-11-10 14:28:29 -0300 | [diff] [blame] | 91 | u32 code; |
Laurent Pinchart | 539b33b | 2014-01-26 18:42:37 -0300 | [diff] [blame] | 92 | u8 op_ch_sel; |
| 93 | bool rgb_out; |
| 94 | bool swap_cb_cr; |
| 95 | u8 op_format_sel; |
| 96 | }; |
| 97 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 98 | struct adv76xx_chip_info { |
| 99 | enum adv76xx_type type; |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 100 | |
| 101 | bool has_afe; |
| 102 | unsigned int max_port; |
| 103 | unsigned int num_dv_ports; |
| 104 | |
| 105 | unsigned int edid_enable_reg; |
| 106 | unsigned int edid_status_reg; |
| 107 | unsigned int lcf_reg; |
| 108 | |
| 109 | unsigned int cable_det_mask; |
| 110 | unsigned int tdms_lock_mask; |
| 111 | unsigned int fmt_change_digital_mask; |
jean-michel.hautbois@vodalys.com | 80f4944 | 2015-02-04 11:16:00 -0300 | [diff] [blame] | 112 | unsigned int cp_csc; |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 113 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 114 | const struct adv76xx_format_info *formats; |
Laurent Pinchart | 539b33b | 2014-01-26 18:42:37 -0300 | [diff] [blame] | 115 | unsigned int nformats; |
| 116 | |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 117 | void (*set_termination)(struct v4l2_subdev *sd, bool enable); |
| 118 | void (*setup_irqs)(struct v4l2_subdev *sd); |
| 119 | unsigned int (*read_hdmi_pixelclock)(struct v4l2_subdev *sd); |
| 120 | unsigned int (*read_cable_det)(struct v4l2_subdev *sd); |
| 121 | |
| 122 | /* 0 = AFE, 1 = HDMI */ |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 123 | const struct adv76xx_reg_seq *recommended_settings[2]; |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 124 | unsigned int num_recommended_settings[2]; |
| 125 | |
| 126 | unsigned long page_mask; |
jean-michel.hautbois@vodalys.com | 5380baa | 2015-04-09 05:25:46 -0300 | [diff] [blame] | 127 | |
| 128 | /* Masks for timings */ |
| 129 | unsigned int linewidth_mask; |
| 130 | unsigned int field0_height_mask; |
| 131 | unsigned int field1_height_mask; |
| 132 | unsigned int hfrontporch_mask; |
| 133 | unsigned int hsync_mask; |
| 134 | unsigned int hbackporch_mask; |
| 135 | unsigned int field0_vfrontporch_mask; |
| 136 | unsigned int field1_vfrontporch_mask; |
| 137 | unsigned int field0_vsync_mask; |
| 138 | unsigned int field1_vsync_mask; |
| 139 | unsigned int field0_vbackporch_mask; |
| 140 | unsigned int field1_vbackporch_mask; |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 141 | }; |
| 142 | |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 143 | /* |
| 144 | ********************************************************************** |
| 145 | * |
| 146 | * Arrays with configuration parameters for the ADV7604 |
| 147 | * |
| 148 | ********************************************************************** |
| 149 | */ |
Laurent Pinchart | c784b1e | 2014-01-29 10:08:58 -0300 | [diff] [blame] | 150 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 151 | struct adv76xx_state { |
| 152 | const struct adv76xx_chip_info *info; |
| 153 | struct adv76xx_platform_data pdata; |
Laurent Pinchart | 539b33b | 2014-01-26 18:42:37 -0300 | [diff] [blame] | 154 | |
Laurent Pinchart | e9d50e9 | 2014-01-30 18:37:08 -0300 | [diff] [blame] | 155 | struct gpio_desc *hpd_gpio[4]; |
| 156 | |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 157 | struct v4l2_subdev sd; |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 158 | struct media_pad pads[ADV76XX_PAD_MAX]; |
Laurent Pinchart | c784b1e | 2014-01-29 10:08:58 -0300 | [diff] [blame] | 159 | unsigned int source_pad; |
Laurent Pinchart | 539b33b | 2014-01-26 18:42:37 -0300 | [diff] [blame] | 160 | |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 161 | struct v4l2_ctrl_handler hdl; |
Laurent Pinchart | 539b33b | 2014-01-26 18:42:37 -0300 | [diff] [blame] | 162 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 163 | enum adv76xx_pad selected_input; |
Laurent Pinchart | 539b33b | 2014-01-26 18:42:37 -0300 | [diff] [blame] | 164 | |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 165 | struct v4l2_dv_timings timings; |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 166 | const struct adv76xx_format_info *format; |
Laurent Pinchart | 539b33b | 2014-01-26 18:42:37 -0300 | [diff] [blame] | 167 | |
Mats Randgaard | 4a31a93 | 2013-12-10 09:45:00 -0300 | [diff] [blame] | 168 | struct { |
| 169 | u8 edid[256]; |
| 170 | u32 present; |
| 171 | unsigned blocks; |
| 172 | } edid; |
Mats Randgaard | dd08beb | 2013-12-10 09:57:09 -0300 | [diff] [blame] | 173 | u16 spa_port_a[2]; |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 174 | struct v4l2_fract aspect_ratio; |
| 175 | u32 rgb_quantization_range; |
| 176 | struct workqueue_struct *work_queues; |
| 177 | struct delayed_work delayed_work_enable_hotplug; |
Hans Verkuil | cf9afb1 | 2012-10-16 10:12:55 -0300 | [diff] [blame] | 178 | bool restart_stdi_once; |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 179 | |
| 180 | /* i2c clients */ |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 181 | struct i2c_client *i2c_clients[ADV76XX_PAGE_MAX]; |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 182 | |
| 183 | /* controls */ |
| 184 | struct v4l2_ctrl *detect_tx_5v_ctrl; |
| 185 | struct v4l2_ctrl *analog_sampling_phase_ctrl; |
| 186 | struct v4l2_ctrl *free_run_color_manual_ctrl; |
| 187 | struct v4l2_ctrl *free_run_color_ctrl; |
| 188 | struct v4l2_ctrl *rgb_quantization_range_ctrl; |
| 189 | }; |
| 190 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 191 | static bool adv76xx_has_afe(struct adv76xx_state *state) |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 192 | { |
| 193 | return state->info->has_afe; |
| 194 | } |
| 195 | |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 196 | /* Supported CEA and DMT timings */ |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 197 | static const struct v4l2_dv_timings adv76xx_timings[] = { |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 198 | V4L2_DV_BT_CEA_720X480P59_94, |
| 199 | V4L2_DV_BT_CEA_720X576P50, |
| 200 | V4L2_DV_BT_CEA_1280X720P24, |
| 201 | V4L2_DV_BT_CEA_1280X720P25, |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 202 | V4L2_DV_BT_CEA_1280X720P50, |
| 203 | V4L2_DV_BT_CEA_1280X720P60, |
| 204 | V4L2_DV_BT_CEA_1920X1080P24, |
| 205 | V4L2_DV_BT_CEA_1920X1080P25, |
| 206 | V4L2_DV_BT_CEA_1920X1080P30, |
| 207 | V4L2_DV_BT_CEA_1920X1080P50, |
| 208 | V4L2_DV_BT_CEA_1920X1080P60, |
| 209 | |
Hans Verkuil | ccbd5bc | 2012-10-16 10:02:05 -0300 | [diff] [blame] | 210 | /* sorted by DMT ID */ |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 211 | V4L2_DV_BT_DMT_640X350P85, |
| 212 | V4L2_DV_BT_DMT_640X400P85, |
| 213 | V4L2_DV_BT_DMT_720X400P85, |
| 214 | V4L2_DV_BT_DMT_640X480P60, |
| 215 | V4L2_DV_BT_DMT_640X480P72, |
| 216 | V4L2_DV_BT_DMT_640X480P75, |
| 217 | V4L2_DV_BT_DMT_640X480P85, |
| 218 | V4L2_DV_BT_DMT_800X600P56, |
| 219 | V4L2_DV_BT_DMT_800X600P60, |
| 220 | V4L2_DV_BT_DMT_800X600P72, |
| 221 | V4L2_DV_BT_DMT_800X600P75, |
| 222 | V4L2_DV_BT_DMT_800X600P85, |
| 223 | V4L2_DV_BT_DMT_848X480P60, |
| 224 | V4L2_DV_BT_DMT_1024X768P60, |
| 225 | V4L2_DV_BT_DMT_1024X768P70, |
| 226 | V4L2_DV_BT_DMT_1024X768P75, |
| 227 | V4L2_DV_BT_DMT_1024X768P85, |
| 228 | V4L2_DV_BT_DMT_1152X864P75, |
| 229 | V4L2_DV_BT_DMT_1280X768P60_RB, |
| 230 | V4L2_DV_BT_DMT_1280X768P60, |
| 231 | V4L2_DV_BT_DMT_1280X768P75, |
| 232 | V4L2_DV_BT_DMT_1280X768P85, |
| 233 | V4L2_DV_BT_DMT_1280X800P60_RB, |
| 234 | V4L2_DV_BT_DMT_1280X800P60, |
| 235 | V4L2_DV_BT_DMT_1280X800P75, |
| 236 | V4L2_DV_BT_DMT_1280X800P85, |
| 237 | V4L2_DV_BT_DMT_1280X960P60, |
| 238 | V4L2_DV_BT_DMT_1280X960P85, |
| 239 | V4L2_DV_BT_DMT_1280X1024P60, |
| 240 | V4L2_DV_BT_DMT_1280X1024P75, |
| 241 | V4L2_DV_BT_DMT_1280X1024P85, |
| 242 | V4L2_DV_BT_DMT_1360X768P60, |
| 243 | V4L2_DV_BT_DMT_1400X1050P60_RB, |
| 244 | V4L2_DV_BT_DMT_1400X1050P60, |
| 245 | V4L2_DV_BT_DMT_1400X1050P75, |
| 246 | V4L2_DV_BT_DMT_1400X1050P85, |
| 247 | V4L2_DV_BT_DMT_1440X900P60_RB, |
| 248 | V4L2_DV_BT_DMT_1440X900P60, |
| 249 | V4L2_DV_BT_DMT_1600X1200P60, |
| 250 | V4L2_DV_BT_DMT_1680X1050P60_RB, |
| 251 | V4L2_DV_BT_DMT_1680X1050P60, |
| 252 | V4L2_DV_BT_DMT_1792X1344P60, |
| 253 | V4L2_DV_BT_DMT_1856X1392P60, |
| 254 | V4L2_DV_BT_DMT_1920X1200P60_RB, |
Martin Bugge | 547ed54 | 2013-12-05 10:01:17 -0300 | [diff] [blame] | 255 | V4L2_DV_BT_DMT_1366X768P60_RB, |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 256 | V4L2_DV_BT_DMT_1366X768P60, |
| 257 | V4L2_DV_BT_DMT_1920X1080P60, |
| 258 | { }, |
| 259 | }; |
| 260 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 261 | struct adv76xx_video_standards { |
Hans Verkuil | ccbd5bc | 2012-10-16 10:02:05 -0300 | [diff] [blame] | 262 | struct v4l2_dv_timings timings; |
| 263 | u8 vid_std; |
| 264 | u8 v_freq; |
| 265 | }; |
| 266 | |
| 267 | /* sorted by number of lines */ |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 268 | static const struct adv76xx_video_standards adv7604_prim_mode_comp[] = { |
Hans Verkuil | ccbd5bc | 2012-10-16 10:02:05 -0300 | [diff] [blame] | 269 | /* { V4L2_DV_BT_CEA_720X480P59_94, 0x0a, 0x00 }, TODO flickering */ |
| 270 | { V4L2_DV_BT_CEA_720X576P50, 0x0b, 0x00 }, |
| 271 | { V4L2_DV_BT_CEA_1280X720P50, 0x19, 0x01 }, |
| 272 | { V4L2_DV_BT_CEA_1280X720P60, 0x19, 0x00 }, |
| 273 | { V4L2_DV_BT_CEA_1920X1080P24, 0x1e, 0x04 }, |
| 274 | { V4L2_DV_BT_CEA_1920X1080P25, 0x1e, 0x03 }, |
| 275 | { V4L2_DV_BT_CEA_1920X1080P30, 0x1e, 0x02 }, |
| 276 | { V4L2_DV_BT_CEA_1920X1080P50, 0x1e, 0x01 }, |
| 277 | { V4L2_DV_BT_CEA_1920X1080P60, 0x1e, 0x00 }, |
| 278 | /* TODO add 1920x1080P60_RB (CVT timing) */ |
| 279 | { }, |
| 280 | }; |
| 281 | |
| 282 | /* sorted by number of lines */ |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 283 | static const struct adv76xx_video_standards adv7604_prim_mode_gr[] = { |
Hans Verkuil | ccbd5bc | 2012-10-16 10:02:05 -0300 | [diff] [blame] | 284 | { V4L2_DV_BT_DMT_640X480P60, 0x08, 0x00 }, |
| 285 | { V4L2_DV_BT_DMT_640X480P72, 0x09, 0x00 }, |
| 286 | { V4L2_DV_BT_DMT_640X480P75, 0x0a, 0x00 }, |
| 287 | { V4L2_DV_BT_DMT_640X480P85, 0x0b, 0x00 }, |
| 288 | { V4L2_DV_BT_DMT_800X600P56, 0x00, 0x00 }, |
| 289 | { V4L2_DV_BT_DMT_800X600P60, 0x01, 0x00 }, |
| 290 | { V4L2_DV_BT_DMT_800X600P72, 0x02, 0x00 }, |
| 291 | { V4L2_DV_BT_DMT_800X600P75, 0x03, 0x00 }, |
| 292 | { V4L2_DV_BT_DMT_800X600P85, 0x04, 0x00 }, |
| 293 | { V4L2_DV_BT_DMT_1024X768P60, 0x0c, 0x00 }, |
| 294 | { V4L2_DV_BT_DMT_1024X768P70, 0x0d, 0x00 }, |
| 295 | { V4L2_DV_BT_DMT_1024X768P75, 0x0e, 0x00 }, |
| 296 | { V4L2_DV_BT_DMT_1024X768P85, 0x0f, 0x00 }, |
| 297 | { V4L2_DV_BT_DMT_1280X1024P60, 0x05, 0x00 }, |
| 298 | { V4L2_DV_BT_DMT_1280X1024P75, 0x06, 0x00 }, |
| 299 | { V4L2_DV_BT_DMT_1360X768P60, 0x12, 0x00 }, |
| 300 | { V4L2_DV_BT_DMT_1366X768P60, 0x13, 0x00 }, |
| 301 | { V4L2_DV_BT_DMT_1400X1050P60, 0x14, 0x00 }, |
| 302 | { V4L2_DV_BT_DMT_1400X1050P75, 0x15, 0x00 }, |
| 303 | { V4L2_DV_BT_DMT_1600X1200P60, 0x16, 0x00 }, /* TODO not tested */ |
| 304 | /* TODO add 1600X1200P60_RB (not a DMT timing) */ |
| 305 | { V4L2_DV_BT_DMT_1680X1050P60, 0x18, 0x00 }, |
| 306 | { V4L2_DV_BT_DMT_1920X1200P60_RB, 0x19, 0x00 }, /* TODO not tested */ |
| 307 | { }, |
| 308 | }; |
| 309 | |
| 310 | /* sorted by number of lines */ |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 311 | static const struct adv76xx_video_standards adv76xx_prim_mode_hdmi_comp[] = { |
Hans Verkuil | ccbd5bc | 2012-10-16 10:02:05 -0300 | [diff] [blame] | 312 | { V4L2_DV_BT_CEA_720X480P59_94, 0x0a, 0x00 }, |
| 313 | { V4L2_DV_BT_CEA_720X576P50, 0x0b, 0x00 }, |
| 314 | { V4L2_DV_BT_CEA_1280X720P50, 0x13, 0x01 }, |
| 315 | { V4L2_DV_BT_CEA_1280X720P60, 0x13, 0x00 }, |
| 316 | { V4L2_DV_BT_CEA_1920X1080P24, 0x1e, 0x04 }, |
| 317 | { V4L2_DV_BT_CEA_1920X1080P25, 0x1e, 0x03 }, |
| 318 | { V4L2_DV_BT_CEA_1920X1080P30, 0x1e, 0x02 }, |
| 319 | { V4L2_DV_BT_CEA_1920X1080P50, 0x1e, 0x01 }, |
| 320 | { V4L2_DV_BT_CEA_1920X1080P60, 0x1e, 0x00 }, |
| 321 | { }, |
| 322 | }; |
| 323 | |
| 324 | /* sorted by number of lines */ |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 325 | static const struct adv76xx_video_standards adv76xx_prim_mode_hdmi_gr[] = { |
Hans Verkuil | ccbd5bc | 2012-10-16 10:02:05 -0300 | [diff] [blame] | 326 | { V4L2_DV_BT_DMT_640X480P60, 0x08, 0x00 }, |
| 327 | { V4L2_DV_BT_DMT_640X480P72, 0x09, 0x00 }, |
| 328 | { V4L2_DV_BT_DMT_640X480P75, 0x0a, 0x00 }, |
| 329 | { V4L2_DV_BT_DMT_640X480P85, 0x0b, 0x00 }, |
| 330 | { V4L2_DV_BT_DMT_800X600P56, 0x00, 0x00 }, |
| 331 | { V4L2_DV_BT_DMT_800X600P60, 0x01, 0x00 }, |
| 332 | { V4L2_DV_BT_DMT_800X600P72, 0x02, 0x00 }, |
| 333 | { V4L2_DV_BT_DMT_800X600P75, 0x03, 0x00 }, |
| 334 | { V4L2_DV_BT_DMT_800X600P85, 0x04, 0x00 }, |
| 335 | { V4L2_DV_BT_DMT_1024X768P60, 0x0c, 0x00 }, |
| 336 | { V4L2_DV_BT_DMT_1024X768P70, 0x0d, 0x00 }, |
| 337 | { V4L2_DV_BT_DMT_1024X768P75, 0x0e, 0x00 }, |
| 338 | { V4L2_DV_BT_DMT_1024X768P85, 0x0f, 0x00 }, |
| 339 | { V4L2_DV_BT_DMT_1280X1024P60, 0x05, 0x00 }, |
| 340 | { V4L2_DV_BT_DMT_1280X1024P75, 0x06, 0x00 }, |
| 341 | { }, |
| 342 | }; |
| 343 | |
Hans Verkuil | 4851983 | 2015-05-07 10:37:57 -0300 | [diff] [blame^] | 344 | static const struct v4l2_event adv76xx_ev_fmt = { |
| 345 | .type = V4L2_EVENT_SOURCE_CHANGE, |
| 346 | .u.src_change.changes = V4L2_EVENT_SRC_CH_RESOLUTION, |
| 347 | }; |
| 348 | |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 349 | /* ----------------------------------------------------------------------- */ |
| 350 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 351 | static inline struct adv76xx_state *to_state(struct v4l2_subdev *sd) |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 352 | { |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 353 | return container_of(sd, struct adv76xx_state, sd); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 354 | } |
| 355 | |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 356 | static inline unsigned htotal(const struct v4l2_bt_timings *t) |
| 357 | { |
Hans Verkuil | eacf8f9 | 2013-07-29 08:40:59 -0300 | [diff] [blame] | 358 | return V4L2_DV_BT_FRAME_WIDTH(t); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 359 | } |
| 360 | |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 361 | static inline unsigned vtotal(const struct v4l2_bt_timings *t) |
| 362 | { |
Hans Verkuil | eacf8f9 | 2013-07-29 08:40:59 -0300 | [diff] [blame] | 363 | return V4L2_DV_BT_FRAME_HEIGHT(t); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | /* ----------------------------------------------------------------------- */ |
| 367 | |
| 368 | static s32 adv_smbus_read_byte_data_check(struct i2c_client *client, |
| 369 | u8 command, bool check) |
| 370 | { |
| 371 | union i2c_smbus_data data; |
| 372 | |
| 373 | if (!i2c_smbus_xfer(client->adapter, client->addr, client->flags, |
| 374 | I2C_SMBUS_READ, command, |
| 375 | I2C_SMBUS_BYTE_DATA, &data)) |
| 376 | return data.byte; |
| 377 | if (check) |
| 378 | v4l_err(client, "error reading %02x, %02x\n", |
| 379 | client->addr, command); |
| 380 | return -EIO; |
| 381 | } |
| 382 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 383 | static s32 adv_smbus_read_byte_data(struct adv76xx_state *state, |
| 384 | enum adv76xx_page page, u8 command) |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 385 | { |
Laurent Pinchart | 05cacb1 | 2014-01-30 16:32:21 -0300 | [diff] [blame] | 386 | return adv_smbus_read_byte_data_check(state->i2c_clients[page], |
| 387 | command, true); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 388 | } |
| 389 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 390 | static s32 adv_smbus_write_byte_data(struct adv76xx_state *state, |
| 391 | enum adv76xx_page page, u8 command, |
Laurent Pinchart | 05cacb1 | 2014-01-30 16:32:21 -0300 | [diff] [blame] | 392 | u8 value) |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 393 | { |
Laurent Pinchart | 05cacb1 | 2014-01-30 16:32:21 -0300 | [diff] [blame] | 394 | struct i2c_client *client = state->i2c_clients[page]; |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 395 | union i2c_smbus_data data; |
| 396 | int err; |
| 397 | int i; |
| 398 | |
| 399 | data.byte = value; |
| 400 | for (i = 0; i < 3; i++) { |
| 401 | err = i2c_smbus_xfer(client->adapter, client->addr, |
| 402 | client->flags, |
| 403 | I2C_SMBUS_WRITE, command, |
| 404 | I2C_SMBUS_BYTE_DATA, &data); |
| 405 | if (!err) |
| 406 | break; |
| 407 | } |
| 408 | if (err < 0) |
| 409 | v4l_err(client, "error writing %02x, %02x, %02x\n", |
| 410 | client->addr, command, value); |
| 411 | return err; |
| 412 | } |
| 413 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 414 | static s32 adv_smbus_write_i2c_block_data(struct adv76xx_state *state, |
| 415 | enum adv76xx_page page, u8 command, |
Laurent Pinchart | 05cacb1 | 2014-01-30 16:32:21 -0300 | [diff] [blame] | 416 | unsigned length, const u8 *values) |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 417 | { |
Laurent Pinchart | 05cacb1 | 2014-01-30 16:32:21 -0300 | [diff] [blame] | 418 | struct i2c_client *client = state->i2c_clients[page]; |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 419 | union i2c_smbus_data data; |
| 420 | |
| 421 | if (length > I2C_SMBUS_BLOCK_MAX) |
| 422 | length = I2C_SMBUS_BLOCK_MAX; |
| 423 | data.block[0] = length; |
| 424 | memcpy(data.block + 1, values, length); |
| 425 | return i2c_smbus_xfer(client->adapter, client->addr, client->flags, |
| 426 | I2C_SMBUS_WRITE, command, |
| 427 | I2C_SMBUS_I2C_BLOCK_DATA, &data); |
| 428 | } |
| 429 | |
| 430 | /* ----------------------------------------------------------------------- */ |
| 431 | |
| 432 | static inline int io_read(struct v4l2_subdev *sd, u8 reg) |
| 433 | { |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 434 | struct adv76xx_state *state = to_state(sd); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 435 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 436 | return adv_smbus_read_byte_data(state, ADV76XX_PAGE_IO, reg); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 437 | } |
| 438 | |
| 439 | static inline int io_write(struct v4l2_subdev *sd, u8 reg, u8 val) |
| 440 | { |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 441 | struct adv76xx_state *state = to_state(sd); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 442 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 443 | return adv_smbus_write_byte_data(state, ADV76XX_PAGE_IO, reg, val); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 444 | } |
| 445 | |
Laurent Pinchart | 22d97e5 | 2014-01-30 17:17:42 -0300 | [diff] [blame] | 446 | static inline int io_write_clr_set(struct v4l2_subdev *sd, u8 reg, u8 mask, u8 val) |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 447 | { |
Laurent Pinchart | 22d97e5 | 2014-01-30 17:17:42 -0300 | [diff] [blame] | 448 | return io_write(sd, reg, (io_read(sd, reg) & ~mask) | val); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 449 | } |
| 450 | |
| 451 | static inline int avlink_read(struct v4l2_subdev *sd, u8 reg) |
| 452 | { |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 453 | struct adv76xx_state *state = to_state(sd); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 454 | |
Laurent Pinchart | 05cacb1 | 2014-01-30 16:32:21 -0300 | [diff] [blame] | 455 | return adv_smbus_read_byte_data(state, ADV7604_PAGE_AVLINK, reg); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 456 | } |
| 457 | |
| 458 | static inline int avlink_write(struct v4l2_subdev *sd, u8 reg, u8 val) |
| 459 | { |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 460 | struct adv76xx_state *state = to_state(sd); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 461 | |
Laurent Pinchart | 05cacb1 | 2014-01-30 16:32:21 -0300 | [diff] [blame] | 462 | return adv_smbus_write_byte_data(state, ADV7604_PAGE_AVLINK, reg, val); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | static inline int cec_read(struct v4l2_subdev *sd, u8 reg) |
| 466 | { |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 467 | struct adv76xx_state *state = to_state(sd); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 468 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 469 | return adv_smbus_read_byte_data(state, ADV76XX_PAGE_CEC, reg); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 470 | } |
| 471 | |
| 472 | static inline int cec_write(struct v4l2_subdev *sd, u8 reg, u8 val) |
| 473 | { |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 474 | struct adv76xx_state *state = to_state(sd); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 475 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 476 | return adv_smbus_write_byte_data(state, ADV76XX_PAGE_CEC, reg, val); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 477 | } |
| 478 | |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 479 | static inline int infoframe_read(struct v4l2_subdev *sd, u8 reg) |
| 480 | { |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 481 | struct adv76xx_state *state = to_state(sd); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 482 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 483 | return adv_smbus_read_byte_data(state, ADV76XX_PAGE_INFOFRAME, reg); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | static inline int infoframe_write(struct v4l2_subdev *sd, u8 reg, u8 val) |
| 487 | { |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 488 | struct adv76xx_state *state = to_state(sd); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 489 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 490 | return adv_smbus_write_byte_data(state, ADV76XX_PAGE_INFOFRAME, |
Laurent Pinchart | 05cacb1 | 2014-01-30 16:32:21 -0300 | [diff] [blame] | 491 | reg, val); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 492 | } |
| 493 | |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 494 | static inline int afe_read(struct v4l2_subdev *sd, u8 reg) |
| 495 | { |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 496 | struct adv76xx_state *state = to_state(sd); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 497 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 498 | return adv_smbus_read_byte_data(state, ADV76XX_PAGE_AFE, reg); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 499 | } |
| 500 | |
| 501 | static inline int afe_write(struct v4l2_subdev *sd, u8 reg, u8 val) |
| 502 | { |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 503 | struct adv76xx_state *state = to_state(sd); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 504 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 505 | return adv_smbus_write_byte_data(state, ADV76XX_PAGE_AFE, reg, val); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 506 | } |
| 507 | |
| 508 | static inline int rep_read(struct v4l2_subdev *sd, u8 reg) |
| 509 | { |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 510 | struct adv76xx_state *state = to_state(sd); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 511 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 512 | return adv_smbus_read_byte_data(state, ADV76XX_PAGE_REP, reg); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 513 | } |
| 514 | |
| 515 | static inline int rep_write(struct v4l2_subdev *sd, u8 reg, u8 val) |
| 516 | { |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 517 | struct adv76xx_state *state = to_state(sd); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 518 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 519 | return adv_smbus_write_byte_data(state, ADV76XX_PAGE_REP, reg, val); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 520 | } |
| 521 | |
Laurent Pinchart | 22d97e5 | 2014-01-30 17:17:42 -0300 | [diff] [blame] | 522 | static inline int rep_write_clr_set(struct v4l2_subdev *sd, u8 reg, u8 mask, u8 val) |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 523 | { |
Laurent Pinchart | 22d97e5 | 2014-01-30 17:17:42 -0300 | [diff] [blame] | 524 | return rep_write(sd, reg, (rep_read(sd, reg) & ~mask) | val); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 525 | } |
| 526 | |
| 527 | static inline int edid_read(struct v4l2_subdev *sd, u8 reg) |
| 528 | { |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 529 | struct adv76xx_state *state = to_state(sd); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 530 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 531 | return adv_smbus_read_byte_data(state, ADV76XX_PAGE_EDID, reg); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 532 | } |
| 533 | |
| 534 | static inline int edid_write(struct v4l2_subdev *sd, u8 reg, u8 val) |
| 535 | { |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 536 | struct adv76xx_state *state = to_state(sd); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 537 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 538 | return adv_smbus_write_byte_data(state, ADV76XX_PAGE_EDID, reg, val); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 539 | } |
| 540 | |
Mats Randgaard | dd08beb | 2013-12-10 09:57:09 -0300 | [diff] [blame] | 541 | static inline int edid_write_block(struct v4l2_subdev *sd, |
| 542 | unsigned len, const u8 *val) |
| 543 | { |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 544 | struct adv76xx_state *state = to_state(sd); |
Mats Randgaard | dd08beb | 2013-12-10 09:57:09 -0300 | [diff] [blame] | 545 | int err = 0; |
| 546 | int i; |
| 547 | |
| 548 | v4l2_dbg(2, debug, sd, "%s: write EDID block (%d byte)\n", __func__, len); |
| 549 | |
| 550 | for (i = 0; !err && i < len; i += I2C_SMBUS_BLOCK_MAX) |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 551 | err = adv_smbus_write_i2c_block_data(state, ADV76XX_PAGE_EDID, |
Laurent Pinchart | 05cacb1 | 2014-01-30 16:32:21 -0300 | [diff] [blame] | 552 | i, I2C_SMBUS_BLOCK_MAX, val + i); |
Mats Randgaard | dd08beb | 2013-12-10 09:57:09 -0300 | [diff] [blame] | 553 | return err; |
| 554 | } |
| 555 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 556 | static void adv76xx_set_hpd(struct adv76xx_state *state, unsigned int hpd) |
Laurent Pinchart | e9d50e9 | 2014-01-30 18:37:08 -0300 | [diff] [blame] | 557 | { |
| 558 | unsigned int i; |
| 559 | |
Uwe Kleine-König | 269bd13 | 2015-03-02 04:00:44 -0300 | [diff] [blame] | 560 | for (i = 0; i < state->info->num_dv_ports; ++i) |
Laurent Pinchart | e9d50e9 | 2014-01-30 18:37:08 -0300 | [diff] [blame] | 561 | gpiod_set_value_cansleep(state->hpd_gpio[i], hpd & BIT(i)); |
Laurent Pinchart | e9d50e9 | 2014-01-30 18:37:08 -0300 | [diff] [blame] | 562 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 563 | v4l2_subdev_notify(&state->sd, ADV76XX_HOTPLUG, &hpd); |
Laurent Pinchart | e9d50e9 | 2014-01-30 18:37:08 -0300 | [diff] [blame] | 564 | } |
| 565 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 566 | static void adv76xx_delayed_work_enable_hotplug(struct work_struct *work) |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 567 | { |
| 568 | struct delayed_work *dwork = to_delayed_work(work); |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 569 | struct adv76xx_state *state = container_of(dwork, struct adv76xx_state, |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 570 | delayed_work_enable_hotplug); |
| 571 | struct v4l2_subdev *sd = &state->sd; |
| 572 | |
| 573 | v4l2_dbg(2, debug, sd, "%s: enable hotplug\n", __func__); |
| 574 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 575 | adv76xx_set_hpd(state, state->edid.present); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 576 | } |
| 577 | |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 578 | static inline int hdmi_read(struct v4l2_subdev *sd, u8 reg) |
| 579 | { |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 580 | struct adv76xx_state *state = to_state(sd); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 581 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 582 | return adv_smbus_read_byte_data(state, ADV76XX_PAGE_HDMI, reg); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 583 | } |
| 584 | |
Laurent Pinchart | 51182a9 | 2014-01-08 19:30:37 -0300 | [diff] [blame] | 585 | static u16 hdmi_read16(struct v4l2_subdev *sd, u8 reg, u16 mask) |
| 586 | { |
| 587 | return ((hdmi_read(sd, reg) << 8) | hdmi_read(sd, reg + 1)) & mask; |
| 588 | } |
| 589 | |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 590 | static inline int hdmi_write(struct v4l2_subdev *sd, u8 reg, u8 val) |
| 591 | { |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 592 | struct adv76xx_state *state = to_state(sd); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 593 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 594 | return adv_smbus_write_byte_data(state, ADV76XX_PAGE_HDMI, reg, val); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 595 | } |
| 596 | |
Laurent Pinchart | 22d97e5 | 2014-01-30 17:17:42 -0300 | [diff] [blame] | 597 | static inline int hdmi_write_clr_set(struct v4l2_subdev *sd, u8 reg, u8 mask, u8 val) |
Mats Randgaard | 4a31a93 | 2013-12-10 09:45:00 -0300 | [diff] [blame] | 598 | { |
Laurent Pinchart | 22d97e5 | 2014-01-30 17:17:42 -0300 | [diff] [blame] | 599 | return hdmi_write(sd, reg, (hdmi_read(sd, reg) & ~mask) | val); |
Mats Randgaard | 4a31a93 | 2013-12-10 09:45:00 -0300 | [diff] [blame] | 600 | } |
| 601 | |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 602 | static inline int test_write(struct v4l2_subdev *sd, u8 reg, u8 val) |
| 603 | { |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 604 | struct adv76xx_state *state = to_state(sd); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 605 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 606 | return adv_smbus_write_byte_data(state, ADV76XX_PAGE_TEST, reg, val); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 607 | } |
| 608 | |
| 609 | static inline int cp_read(struct v4l2_subdev *sd, u8 reg) |
| 610 | { |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 611 | struct adv76xx_state *state = to_state(sd); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 612 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 613 | return adv_smbus_read_byte_data(state, ADV76XX_PAGE_CP, reg); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 614 | } |
| 615 | |
Laurent Pinchart | 51182a9 | 2014-01-08 19:30:37 -0300 | [diff] [blame] | 616 | static u16 cp_read16(struct v4l2_subdev *sd, u8 reg, u16 mask) |
| 617 | { |
| 618 | return ((cp_read(sd, reg) << 8) | cp_read(sd, reg + 1)) & mask; |
| 619 | } |
| 620 | |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 621 | static inline int cp_write(struct v4l2_subdev *sd, u8 reg, u8 val) |
| 622 | { |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 623 | struct adv76xx_state *state = to_state(sd); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 624 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 625 | return adv_smbus_write_byte_data(state, ADV76XX_PAGE_CP, reg, val); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 626 | } |
| 627 | |
Laurent Pinchart | 22d97e5 | 2014-01-30 17:17:42 -0300 | [diff] [blame] | 628 | static inline int cp_write_clr_set(struct v4l2_subdev *sd, u8 reg, u8 mask, u8 val) |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 629 | { |
Laurent Pinchart | 22d97e5 | 2014-01-30 17:17:42 -0300 | [diff] [blame] | 630 | return cp_write(sd, reg, (cp_read(sd, reg) & ~mask) | val); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 631 | } |
| 632 | |
| 633 | static inline int vdp_read(struct v4l2_subdev *sd, u8 reg) |
| 634 | { |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 635 | struct adv76xx_state *state = to_state(sd); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 636 | |
Laurent Pinchart | 05cacb1 | 2014-01-30 16:32:21 -0300 | [diff] [blame] | 637 | return adv_smbus_read_byte_data(state, ADV7604_PAGE_VDP, reg); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 638 | } |
| 639 | |
| 640 | static inline int vdp_write(struct v4l2_subdev *sd, u8 reg, u8 val) |
| 641 | { |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 642 | struct adv76xx_state *state = to_state(sd); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 643 | |
Laurent Pinchart | 05cacb1 | 2014-01-30 16:32:21 -0300 | [diff] [blame] | 644 | return adv_smbus_write_byte_data(state, ADV7604_PAGE_VDP, reg, val); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 645 | } |
| 646 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 647 | #define ADV76XX_REG(page, offset) (((page) << 8) | (offset)) |
| 648 | #define ADV76XX_REG_SEQ_TERM 0xffff |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 649 | |
| 650 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 651 | static int adv76xx_read_reg(struct v4l2_subdev *sd, unsigned int reg) |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 652 | { |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 653 | struct adv76xx_state *state = to_state(sd); |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 654 | unsigned int page = reg >> 8; |
| 655 | |
| 656 | if (!(BIT(page) & state->info->page_mask)) |
| 657 | return -EINVAL; |
| 658 | |
| 659 | reg &= 0xff; |
| 660 | |
Laurent Pinchart | 05cacb1 | 2014-01-30 16:32:21 -0300 | [diff] [blame] | 661 | return adv_smbus_read_byte_data(state, page, reg); |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 662 | } |
| 663 | #endif |
| 664 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 665 | static int adv76xx_write_reg(struct v4l2_subdev *sd, unsigned int reg, u8 val) |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 666 | { |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 667 | struct adv76xx_state *state = to_state(sd); |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 668 | unsigned int page = reg >> 8; |
| 669 | |
| 670 | if (!(BIT(page) & state->info->page_mask)) |
| 671 | return -EINVAL; |
| 672 | |
| 673 | reg &= 0xff; |
| 674 | |
Laurent Pinchart | 05cacb1 | 2014-01-30 16:32:21 -0300 | [diff] [blame] | 675 | return adv_smbus_write_byte_data(state, page, reg, val); |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 676 | } |
| 677 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 678 | static void adv76xx_write_reg_seq(struct v4l2_subdev *sd, |
| 679 | const struct adv76xx_reg_seq *reg_seq) |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 680 | { |
| 681 | unsigned int i; |
| 682 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 683 | for (i = 0; reg_seq[i].reg != ADV76XX_REG_SEQ_TERM; i++) |
| 684 | adv76xx_write_reg(sd, reg_seq[i].reg, reg_seq[i].val); |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 685 | } |
| 686 | |
Laurent Pinchart | 539b33b | 2014-01-26 18:42:37 -0300 | [diff] [blame] | 687 | /* ----------------------------------------------------------------------------- |
| 688 | * Format helpers |
| 689 | */ |
| 690 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 691 | static const struct adv76xx_format_info adv7604_formats[] = { |
| 692 | { MEDIA_BUS_FMT_RGB888_1X24, ADV76XX_OP_CH_SEL_RGB, true, false, |
| 693 | ADV76XX_OP_MODE_SEL_SDR_444 | ADV76XX_OP_FORMAT_SEL_8BIT }, |
| 694 | { MEDIA_BUS_FMT_YUYV8_2X8, ADV76XX_OP_CH_SEL_RGB, false, false, |
| 695 | ADV76XX_OP_MODE_SEL_SDR_422 | ADV76XX_OP_FORMAT_SEL_8BIT }, |
| 696 | { MEDIA_BUS_FMT_YVYU8_2X8, ADV76XX_OP_CH_SEL_RGB, false, true, |
| 697 | ADV76XX_OP_MODE_SEL_SDR_422 | ADV76XX_OP_FORMAT_SEL_8BIT }, |
| 698 | { MEDIA_BUS_FMT_YUYV10_2X10, ADV76XX_OP_CH_SEL_RGB, false, false, |
| 699 | ADV76XX_OP_MODE_SEL_SDR_422 | ADV7604_OP_FORMAT_SEL_10BIT }, |
| 700 | { MEDIA_BUS_FMT_YVYU10_2X10, ADV76XX_OP_CH_SEL_RGB, false, true, |
| 701 | ADV76XX_OP_MODE_SEL_SDR_422 | ADV7604_OP_FORMAT_SEL_10BIT }, |
| 702 | { MEDIA_BUS_FMT_YUYV12_2X12, ADV76XX_OP_CH_SEL_RGB, false, false, |
| 703 | ADV76XX_OP_MODE_SEL_SDR_422 | ADV76XX_OP_FORMAT_SEL_12BIT }, |
| 704 | { MEDIA_BUS_FMT_YVYU12_2X12, ADV76XX_OP_CH_SEL_RGB, false, true, |
| 705 | ADV76XX_OP_MODE_SEL_SDR_422 | ADV76XX_OP_FORMAT_SEL_12BIT }, |
| 706 | { MEDIA_BUS_FMT_UYVY8_1X16, ADV76XX_OP_CH_SEL_RBG, false, false, |
| 707 | ADV76XX_OP_MODE_SEL_SDR_422_2X | ADV76XX_OP_FORMAT_SEL_8BIT }, |
| 708 | { MEDIA_BUS_FMT_VYUY8_1X16, ADV76XX_OP_CH_SEL_RBG, false, true, |
| 709 | ADV76XX_OP_MODE_SEL_SDR_422_2X | ADV76XX_OP_FORMAT_SEL_8BIT }, |
| 710 | { MEDIA_BUS_FMT_YUYV8_1X16, ADV76XX_OP_CH_SEL_RGB, false, false, |
| 711 | ADV76XX_OP_MODE_SEL_SDR_422_2X | ADV76XX_OP_FORMAT_SEL_8BIT }, |
| 712 | { MEDIA_BUS_FMT_YVYU8_1X16, ADV76XX_OP_CH_SEL_RGB, false, true, |
| 713 | ADV76XX_OP_MODE_SEL_SDR_422_2X | ADV76XX_OP_FORMAT_SEL_8BIT }, |
| 714 | { MEDIA_BUS_FMT_UYVY10_1X20, ADV76XX_OP_CH_SEL_RBG, false, false, |
| 715 | ADV76XX_OP_MODE_SEL_SDR_422_2X | ADV7604_OP_FORMAT_SEL_10BIT }, |
| 716 | { MEDIA_BUS_FMT_VYUY10_1X20, ADV76XX_OP_CH_SEL_RBG, false, true, |
| 717 | ADV76XX_OP_MODE_SEL_SDR_422_2X | ADV7604_OP_FORMAT_SEL_10BIT }, |
| 718 | { MEDIA_BUS_FMT_YUYV10_1X20, ADV76XX_OP_CH_SEL_RGB, false, false, |
| 719 | ADV76XX_OP_MODE_SEL_SDR_422_2X | ADV7604_OP_FORMAT_SEL_10BIT }, |
| 720 | { MEDIA_BUS_FMT_YVYU10_1X20, ADV76XX_OP_CH_SEL_RGB, false, true, |
| 721 | ADV76XX_OP_MODE_SEL_SDR_422_2X | ADV7604_OP_FORMAT_SEL_10BIT }, |
| 722 | { MEDIA_BUS_FMT_UYVY12_1X24, ADV76XX_OP_CH_SEL_RBG, false, false, |
| 723 | ADV76XX_OP_MODE_SEL_SDR_422_2X | ADV76XX_OP_FORMAT_SEL_12BIT }, |
| 724 | { MEDIA_BUS_FMT_VYUY12_1X24, ADV76XX_OP_CH_SEL_RBG, false, true, |
| 725 | ADV76XX_OP_MODE_SEL_SDR_422_2X | ADV76XX_OP_FORMAT_SEL_12BIT }, |
| 726 | { MEDIA_BUS_FMT_YUYV12_1X24, ADV76XX_OP_CH_SEL_RGB, false, false, |
| 727 | ADV76XX_OP_MODE_SEL_SDR_422_2X | ADV76XX_OP_FORMAT_SEL_12BIT }, |
| 728 | { MEDIA_BUS_FMT_YVYU12_1X24, ADV76XX_OP_CH_SEL_RGB, false, true, |
| 729 | ADV76XX_OP_MODE_SEL_SDR_422_2X | ADV76XX_OP_FORMAT_SEL_12BIT }, |
Laurent Pinchart | 539b33b | 2014-01-26 18:42:37 -0300 | [diff] [blame] | 730 | }; |
| 731 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 732 | static const struct adv76xx_format_info adv7611_formats[] = { |
| 733 | { MEDIA_BUS_FMT_RGB888_1X24, ADV76XX_OP_CH_SEL_RGB, true, false, |
| 734 | ADV76XX_OP_MODE_SEL_SDR_444 | ADV76XX_OP_FORMAT_SEL_8BIT }, |
| 735 | { MEDIA_BUS_FMT_YUYV8_2X8, ADV76XX_OP_CH_SEL_RGB, false, false, |
| 736 | ADV76XX_OP_MODE_SEL_SDR_422 | ADV76XX_OP_FORMAT_SEL_8BIT }, |
| 737 | { MEDIA_BUS_FMT_YVYU8_2X8, ADV76XX_OP_CH_SEL_RGB, false, true, |
| 738 | ADV76XX_OP_MODE_SEL_SDR_422 | ADV76XX_OP_FORMAT_SEL_8BIT }, |
| 739 | { MEDIA_BUS_FMT_YUYV12_2X12, ADV76XX_OP_CH_SEL_RGB, false, false, |
| 740 | ADV76XX_OP_MODE_SEL_SDR_422 | ADV76XX_OP_FORMAT_SEL_12BIT }, |
| 741 | { MEDIA_BUS_FMT_YVYU12_2X12, ADV76XX_OP_CH_SEL_RGB, false, true, |
| 742 | ADV76XX_OP_MODE_SEL_SDR_422 | ADV76XX_OP_FORMAT_SEL_12BIT }, |
| 743 | { MEDIA_BUS_FMT_UYVY8_1X16, ADV76XX_OP_CH_SEL_RBG, false, false, |
| 744 | ADV76XX_OP_MODE_SEL_SDR_422_2X | ADV76XX_OP_FORMAT_SEL_8BIT }, |
| 745 | { MEDIA_BUS_FMT_VYUY8_1X16, ADV76XX_OP_CH_SEL_RBG, false, true, |
| 746 | ADV76XX_OP_MODE_SEL_SDR_422_2X | ADV76XX_OP_FORMAT_SEL_8BIT }, |
| 747 | { MEDIA_BUS_FMT_YUYV8_1X16, ADV76XX_OP_CH_SEL_RGB, false, false, |
| 748 | ADV76XX_OP_MODE_SEL_SDR_422_2X | ADV76XX_OP_FORMAT_SEL_8BIT }, |
| 749 | { MEDIA_BUS_FMT_YVYU8_1X16, ADV76XX_OP_CH_SEL_RGB, false, true, |
| 750 | ADV76XX_OP_MODE_SEL_SDR_422_2X | ADV76XX_OP_FORMAT_SEL_8BIT }, |
| 751 | { MEDIA_BUS_FMT_UYVY12_1X24, ADV76XX_OP_CH_SEL_RBG, false, false, |
| 752 | ADV76XX_OP_MODE_SEL_SDR_422_2X | ADV76XX_OP_FORMAT_SEL_12BIT }, |
| 753 | { MEDIA_BUS_FMT_VYUY12_1X24, ADV76XX_OP_CH_SEL_RBG, false, true, |
| 754 | ADV76XX_OP_MODE_SEL_SDR_422_2X | ADV76XX_OP_FORMAT_SEL_12BIT }, |
| 755 | { MEDIA_BUS_FMT_YUYV12_1X24, ADV76XX_OP_CH_SEL_RGB, false, false, |
| 756 | ADV76XX_OP_MODE_SEL_SDR_422_2X | ADV76XX_OP_FORMAT_SEL_12BIT }, |
| 757 | { MEDIA_BUS_FMT_YVYU12_1X24, ADV76XX_OP_CH_SEL_RGB, false, true, |
| 758 | ADV76XX_OP_MODE_SEL_SDR_422_2X | ADV76XX_OP_FORMAT_SEL_12BIT }, |
Laurent Pinchart | 539b33b | 2014-01-26 18:42:37 -0300 | [diff] [blame] | 759 | }; |
| 760 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 761 | static const struct adv76xx_format_info * |
| 762 | adv76xx_format_info(struct adv76xx_state *state, u32 code) |
Laurent Pinchart | 539b33b | 2014-01-26 18:42:37 -0300 | [diff] [blame] | 763 | { |
| 764 | unsigned int i; |
| 765 | |
| 766 | for (i = 0; i < state->info->nformats; ++i) { |
| 767 | if (state->info->formats[i].code == code) |
| 768 | return &state->info->formats[i]; |
| 769 | } |
| 770 | |
| 771 | return NULL; |
| 772 | } |
| 773 | |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 774 | /* ----------------------------------------------------------------------- */ |
| 775 | |
Mats Randgaard | 4a31a93 | 2013-12-10 09:45:00 -0300 | [diff] [blame] | 776 | static inline bool is_analog_input(struct v4l2_subdev *sd) |
| 777 | { |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 778 | struct adv76xx_state *state = to_state(sd); |
Mats Randgaard | 4a31a93 | 2013-12-10 09:45:00 -0300 | [diff] [blame] | 779 | |
Laurent Pinchart | c784b1e | 2014-01-29 10:08:58 -0300 | [diff] [blame] | 780 | return state->selected_input == ADV7604_PAD_VGA_RGB || |
| 781 | state->selected_input == ADV7604_PAD_VGA_COMP; |
Mats Randgaard | 4a31a93 | 2013-12-10 09:45:00 -0300 | [diff] [blame] | 782 | } |
| 783 | |
| 784 | static inline bool is_digital_input(struct v4l2_subdev *sd) |
| 785 | { |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 786 | struct adv76xx_state *state = to_state(sd); |
Mats Randgaard | 4a31a93 | 2013-12-10 09:45:00 -0300 | [diff] [blame] | 787 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 788 | return state->selected_input == ADV76XX_PAD_HDMI_PORT_A || |
Laurent Pinchart | c784b1e | 2014-01-29 10:08:58 -0300 | [diff] [blame] | 789 | state->selected_input == ADV7604_PAD_HDMI_PORT_B || |
| 790 | state->selected_input == ADV7604_PAD_HDMI_PORT_C || |
| 791 | state->selected_input == ADV7604_PAD_HDMI_PORT_D; |
Mats Randgaard | 4a31a93 | 2013-12-10 09:45:00 -0300 | [diff] [blame] | 792 | } |
| 793 | |
| 794 | /* ----------------------------------------------------------------------- */ |
| 795 | |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 796 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 797 | static void adv76xx_inv_register(struct v4l2_subdev *sd) |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 798 | { |
| 799 | v4l2_info(sd, "0x000-0x0ff: IO Map\n"); |
| 800 | v4l2_info(sd, "0x100-0x1ff: AVLink Map\n"); |
| 801 | v4l2_info(sd, "0x200-0x2ff: CEC Map\n"); |
| 802 | v4l2_info(sd, "0x300-0x3ff: InfoFrame Map\n"); |
| 803 | v4l2_info(sd, "0x400-0x4ff: ESDP Map\n"); |
| 804 | v4l2_info(sd, "0x500-0x5ff: DPP Map\n"); |
| 805 | v4l2_info(sd, "0x600-0x6ff: AFE Map\n"); |
| 806 | v4l2_info(sd, "0x700-0x7ff: Repeater Map\n"); |
| 807 | v4l2_info(sd, "0x800-0x8ff: EDID Map\n"); |
| 808 | v4l2_info(sd, "0x900-0x9ff: HDMI Map\n"); |
| 809 | v4l2_info(sd, "0xa00-0xaff: Test Map\n"); |
| 810 | v4l2_info(sd, "0xb00-0xbff: CP Map\n"); |
| 811 | v4l2_info(sd, "0xc00-0xcff: VDP Map\n"); |
| 812 | } |
| 813 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 814 | static int adv76xx_g_register(struct v4l2_subdev *sd, |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 815 | struct v4l2_dbg_register *reg) |
| 816 | { |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 817 | int ret; |
| 818 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 819 | ret = adv76xx_read_reg(sd, reg->reg); |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 820 | if (ret < 0) { |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 821 | v4l2_info(sd, "Register %03llx not supported\n", reg->reg); |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 822 | adv76xx_inv_register(sd); |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 823 | return ret; |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 824 | } |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 825 | |
| 826 | reg->size = 1; |
| 827 | reg->val = ret; |
| 828 | |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 829 | return 0; |
| 830 | } |
| 831 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 832 | static int adv76xx_s_register(struct v4l2_subdev *sd, |
Hans Verkuil | 977ba3b | 2013-03-24 08:28:46 -0300 | [diff] [blame] | 833 | const struct v4l2_dbg_register *reg) |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 834 | { |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 835 | int ret; |
Hans Verkuil | 1577461 | 2013-12-10 10:02:43 -0300 | [diff] [blame] | 836 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 837 | ret = adv76xx_write_reg(sd, reg->reg, reg->val); |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 838 | if (ret < 0) { |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 839 | v4l2_info(sd, "Register %03llx not supported\n", reg->reg); |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 840 | adv76xx_inv_register(sd); |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 841 | return ret; |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 842 | } |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 843 | |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 844 | return 0; |
| 845 | } |
| 846 | #endif |
| 847 | |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 848 | static unsigned int adv7604_read_cable_det(struct v4l2_subdev *sd) |
| 849 | { |
| 850 | u8 value = io_read(sd, 0x6f); |
| 851 | |
| 852 | return ((value & 0x10) >> 4) |
| 853 | | ((value & 0x08) >> 2) |
| 854 | | ((value & 0x04) << 0) |
| 855 | | ((value & 0x02) << 2); |
| 856 | } |
| 857 | |
| 858 | static unsigned int adv7611_read_cable_det(struct v4l2_subdev *sd) |
| 859 | { |
| 860 | u8 value = io_read(sd, 0x6f); |
| 861 | |
| 862 | return value & 1; |
| 863 | } |
| 864 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 865 | static int adv76xx_s_detect_tx_5v_ctrl(struct v4l2_subdev *sd) |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 866 | { |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 867 | struct adv76xx_state *state = to_state(sd); |
| 868 | const struct adv76xx_chip_info *info = state->info; |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 869 | |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 870 | return v4l2_ctrl_s_ctrl(state->detect_tx_5v_ctrl, |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 871 | info->read_cable_det(sd)); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 872 | } |
| 873 | |
Hans Verkuil | ccbd5bc | 2012-10-16 10:02:05 -0300 | [diff] [blame] | 874 | static int find_and_set_predefined_video_timings(struct v4l2_subdev *sd, |
| 875 | u8 prim_mode, |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 876 | const struct adv76xx_video_standards *predef_vid_timings, |
Hans Verkuil | ccbd5bc | 2012-10-16 10:02:05 -0300 | [diff] [blame] | 877 | const struct v4l2_dv_timings *timings) |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 878 | { |
Hans Verkuil | ccbd5bc | 2012-10-16 10:02:05 -0300 | [diff] [blame] | 879 | int i; |
| 880 | |
| 881 | for (i = 0; predef_vid_timings[i].timings.bt.width; i++) { |
Hans Verkuil | ef1ed8f | 2013-08-15 08:28:47 -0300 | [diff] [blame] | 882 | if (!v4l2_match_dv_timings(timings, &predef_vid_timings[i].timings, |
Mats Randgaard | 4a31a93 | 2013-12-10 09:45:00 -0300 | [diff] [blame] | 883 | is_digital_input(sd) ? 250000 : 1000000)) |
Hans Verkuil | ccbd5bc | 2012-10-16 10:02:05 -0300 | [diff] [blame] | 884 | continue; |
| 885 | io_write(sd, 0x00, predef_vid_timings[i].vid_std); /* video std */ |
| 886 | io_write(sd, 0x01, (predef_vid_timings[i].v_freq << 4) + |
| 887 | prim_mode); /* v_freq and prim mode */ |
| 888 | return 0; |
| 889 | } |
| 890 | |
| 891 | return -1; |
| 892 | } |
| 893 | |
| 894 | static int configure_predefined_video_timings(struct v4l2_subdev *sd, |
| 895 | struct v4l2_dv_timings *timings) |
| 896 | { |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 897 | struct adv76xx_state *state = to_state(sd); |
Hans Verkuil | ccbd5bc | 2012-10-16 10:02:05 -0300 | [diff] [blame] | 898 | int err; |
| 899 | |
| 900 | v4l2_dbg(1, debug, sd, "%s", __func__); |
| 901 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 902 | if (adv76xx_has_afe(state)) { |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 903 | /* reset to default values */ |
| 904 | io_write(sd, 0x16, 0x43); |
| 905 | io_write(sd, 0x17, 0x5a); |
| 906 | } |
Hans Verkuil | ccbd5bc | 2012-10-16 10:02:05 -0300 | [diff] [blame] | 907 | /* disable embedded syncs for auto graphics mode */ |
Laurent Pinchart | 22d97e5 | 2014-01-30 17:17:42 -0300 | [diff] [blame] | 908 | cp_write_clr_set(sd, 0x81, 0x10, 0x00); |
Hans Verkuil | ccbd5bc | 2012-10-16 10:02:05 -0300 | [diff] [blame] | 909 | cp_write(sd, 0x8f, 0x00); |
| 910 | cp_write(sd, 0x90, 0x00); |
| 911 | cp_write(sd, 0xa2, 0x00); |
| 912 | cp_write(sd, 0xa3, 0x00); |
| 913 | cp_write(sd, 0xa4, 0x00); |
| 914 | cp_write(sd, 0xa5, 0x00); |
| 915 | cp_write(sd, 0xa6, 0x00); |
| 916 | cp_write(sd, 0xa7, 0x00); |
| 917 | cp_write(sd, 0xab, 0x00); |
| 918 | cp_write(sd, 0xac, 0x00); |
| 919 | |
Mats Randgaard | 4a31a93 | 2013-12-10 09:45:00 -0300 | [diff] [blame] | 920 | if (is_analog_input(sd)) { |
Hans Verkuil | ccbd5bc | 2012-10-16 10:02:05 -0300 | [diff] [blame] | 921 | err = find_and_set_predefined_video_timings(sd, |
| 922 | 0x01, adv7604_prim_mode_comp, timings); |
| 923 | if (err) |
| 924 | err = find_and_set_predefined_video_timings(sd, |
| 925 | 0x02, adv7604_prim_mode_gr, timings); |
Mats Randgaard | 4a31a93 | 2013-12-10 09:45:00 -0300 | [diff] [blame] | 926 | } else if (is_digital_input(sd)) { |
Hans Verkuil | ccbd5bc | 2012-10-16 10:02:05 -0300 | [diff] [blame] | 927 | err = find_and_set_predefined_video_timings(sd, |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 928 | 0x05, adv76xx_prim_mode_hdmi_comp, timings); |
Hans Verkuil | ccbd5bc | 2012-10-16 10:02:05 -0300 | [diff] [blame] | 929 | if (err) |
| 930 | err = find_and_set_predefined_video_timings(sd, |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 931 | 0x06, adv76xx_prim_mode_hdmi_gr, timings); |
Mats Randgaard | 4a31a93 | 2013-12-10 09:45:00 -0300 | [diff] [blame] | 932 | } else { |
| 933 | v4l2_dbg(2, debug, sd, "%s: Unknown port %d selected\n", |
| 934 | __func__, state->selected_input); |
Hans Verkuil | ccbd5bc | 2012-10-16 10:02:05 -0300 | [diff] [blame] | 935 | err = -1; |
Hans Verkuil | ccbd5bc | 2012-10-16 10:02:05 -0300 | [diff] [blame] | 936 | } |
| 937 | |
| 938 | |
| 939 | return err; |
| 940 | } |
| 941 | |
| 942 | static void configure_custom_video_timings(struct v4l2_subdev *sd, |
| 943 | const struct v4l2_bt_timings *bt) |
| 944 | { |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 945 | struct adv76xx_state *state = to_state(sd); |
Hans Verkuil | ccbd5bc | 2012-10-16 10:02:05 -0300 | [diff] [blame] | 946 | u32 width = htotal(bt); |
| 947 | u32 height = vtotal(bt); |
| 948 | u16 cp_start_sav = bt->hsync + bt->hbackporch - 4; |
| 949 | u16 cp_start_eav = width - bt->hfrontporch; |
| 950 | u16 cp_start_vbi = height - bt->vfrontporch; |
| 951 | u16 cp_end_vbi = bt->vsync + bt->vbackporch; |
| 952 | u16 ch1_fr_ll = (((u32)bt->pixelclock / 100) > 0) ? |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 953 | ((width * (ADV76XX_FSC / 100)) / ((u32)bt->pixelclock / 100)) : 0; |
Hans Verkuil | ccbd5bc | 2012-10-16 10:02:05 -0300 | [diff] [blame] | 954 | const u8 pll[2] = { |
| 955 | 0xc0 | ((width >> 8) & 0x1f), |
| 956 | width & 0xff |
| 957 | }; |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 958 | |
| 959 | v4l2_dbg(2, debug, sd, "%s\n", __func__); |
| 960 | |
Mats Randgaard | 4a31a93 | 2013-12-10 09:45:00 -0300 | [diff] [blame] | 961 | if (is_analog_input(sd)) { |
Hans Verkuil | ccbd5bc | 2012-10-16 10:02:05 -0300 | [diff] [blame] | 962 | /* auto graphics */ |
| 963 | io_write(sd, 0x00, 0x07); /* video std */ |
| 964 | io_write(sd, 0x01, 0x02); /* prim mode */ |
| 965 | /* enable embedded syncs for auto graphics mode */ |
Laurent Pinchart | 22d97e5 | 2014-01-30 17:17:42 -0300 | [diff] [blame] | 966 | cp_write_clr_set(sd, 0x81, 0x10, 0x10); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 967 | |
Hans Verkuil | ccbd5bc | 2012-10-16 10:02:05 -0300 | [diff] [blame] | 968 | /* Should only be set in auto-graphics mode [REF_02, p. 91-92] */ |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 969 | /* setup PLL_DIV_MAN_EN and PLL_DIV_RATIO */ |
| 970 | /* IO-map reg. 0x16 and 0x17 should be written in sequence */ |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 971 | if (adv_smbus_write_i2c_block_data(state, ADV76XX_PAGE_IO, |
Laurent Pinchart | 05cacb1 | 2014-01-30 16:32:21 -0300 | [diff] [blame] | 972 | 0x16, 2, pll)) |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 973 | v4l2_err(sd, "writing to reg 0x16 and 0x17 failed\n"); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 974 | |
| 975 | /* active video - horizontal timing */ |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 976 | cp_write(sd, 0xa2, (cp_start_sav >> 4) & 0xff); |
Hans Verkuil | ccbd5bc | 2012-10-16 10:02:05 -0300 | [diff] [blame] | 977 | cp_write(sd, 0xa3, ((cp_start_sav & 0x0f) << 4) | |
Mats Randgaard | 4a31a93 | 2013-12-10 09:45:00 -0300 | [diff] [blame] | 978 | ((cp_start_eav >> 8) & 0x0f)); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 979 | cp_write(sd, 0xa4, cp_start_eav & 0xff); |
| 980 | |
| 981 | /* active video - vertical timing */ |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 982 | cp_write(sd, 0xa5, (cp_start_vbi >> 4) & 0xff); |
Hans Verkuil | ccbd5bc | 2012-10-16 10:02:05 -0300 | [diff] [blame] | 983 | cp_write(sd, 0xa6, ((cp_start_vbi & 0xf) << 4) | |
Mats Randgaard | 4a31a93 | 2013-12-10 09:45:00 -0300 | [diff] [blame] | 984 | ((cp_end_vbi >> 8) & 0xf)); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 985 | cp_write(sd, 0xa7, cp_end_vbi & 0xff); |
Mats Randgaard | 4a31a93 | 2013-12-10 09:45:00 -0300 | [diff] [blame] | 986 | } else if (is_digital_input(sd)) { |
Hans Verkuil | ccbd5bc | 2012-10-16 10:02:05 -0300 | [diff] [blame] | 987 | /* set default prim_mode/vid_std for HDMI |
Jonathan McCrohan | 39c1cb2 | 2013-10-20 21:34:01 -0300 | [diff] [blame] | 988 | according to [REF_03, c. 4.2] */ |
Hans Verkuil | ccbd5bc | 2012-10-16 10:02:05 -0300 | [diff] [blame] | 989 | io_write(sd, 0x00, 0x02); /* video std */ |
| 990 | io_write(sd, 0x01, 0x06); /* prim mode */ |
Mats Randgaard | 4a31a93 | 2013-12-10 09:45:00 -0300 | [diff] [blame] | 991 | } else { |
| 992 | v4l2_dbg(2, debug, sd, "%s: Unknown port %d selected\n", |
| 993 | __func__, state->selected_input); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 994 | } |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 995 | |
Hans Verkuil | ccbd5bc | 2012-10-16 10:02:05 -0300 | [diff] [blame] | 996 | cp_write(sd, 0x8f, (ch1_fr_ll >> 8) & 0x7); |
| 997 | cp_write(sd, 0x90, ch1_fr_ll & 0xff); |
| 998 | cp_write(sd, 0xab, (height >> 4) & 0xff); |
| 999 | cp_write(sd, 0xac, (height & 0x0f) << 4); |
| 1000 | } |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1001 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1002 | static void adv76xx_set_offset(struct v4l2_subdev *sd, bool auto_offset, u16 offset_a, u16 offset_b, u16 offset_c) |
Mats Randgaard | 5c6c634 | 2013-12-05 10:39:04 -0300 | [diff] [blame] | 1003 | { |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1004 | struct adv76xx_state *state = to_state(sd); |
Mats Randgaard | 5c6c634 | 2013-12-05 10:39:04 -0300 | [diff] [blame] | 1005 | u8 offset_buf[4]; |
| 1006 | |
| 1007 | if (auto_offset) { |
| 1008 | offset_a = 0x3ff; |
| 1009 | offset_b = 0x3ff; |
| 1010 | offset_c = 0x3ff; |
| 1011 | } |
| 1012 | |
| 1013 | v4l2_dbg(2, debug, sd, "%s: %s offset: a = 0x%x, b = 0x%x, c = 0x%x\n", |
| 1014 | __func__, auto_offset ? "Auto" : "Manual", |
| 1015 | offset_a, offset_b, offset_c); |
| 1016 | |
| 1017 | offset_buf[0] = (cp_read(sd, 0x77) & 0xc0) | ((offset_a & 0x3f0) >> 4); |
| 1018 | offset_buf[1] = ((offset_a & 0x00f) << 4) | ((offset_b & 0x3c0) >> 6); |
| 1019 | offset_buf[2] = ((offset_b & 0x03f) << 2) | ((offset_c & 0x300) >> 8); |
| 1020 | offset_buf[3] = offset_c & 0x0ff; |
| 1021 | |
| 1022 | /* Registers must be written in this order with no i2c access in between */ |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1023 | if (adv_smbus_write_i2c_block_data(state, ADV76XX_PAGE_CP, |
Laurent Pinchart | 05cacb1 | 2014-01-30 16:32:21 -0300 | [diff] [blame] | 1024 | 0x77, 4, offset_buf)) |
Mats Randgaard | 5c6c634 | 2013-12-05 10:39:04 -0300 | [diff] [blame] | 1025 | v4l2_err(sd, "%s: i2c error writing to CP reg 0x77, 0x78, 0x79, 0x7a\n", __func__); |
| 1026 | } |
| 1027 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1028 | static void adv76xx_set_gain(struct v4l2_subdev *sd, bool auto_gain, u16 gain_a, u16 gain_b, u16 gain_c) |
Mats Randgaard | 5c6c634 | 2013-12-05 10:39:04 -0300 | [diff] [blame] | 1029 | { |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1030 | struct adv76xx_state *state = to_state(sd); |
Mats Randgaard | 5c6c634 | 2013-12-05 10:39:04 -0300 | [diff] [blame] | 1031 | u8 gain_buf[4]; |
| 1032 | u8 gain_man = 1; |
| 1033 | u8 agc_mode_man = 1; |
| 1034 | |
| 1035 | if (auto_gain) { |
| 1036 | gain_man = 0; |
| 1037 | agc_mode_man = 0; |
| 1038 | gain_a = 0x100; |
| 1039 | gain_b = 0x100; |
| 1040 | gain_c = 0x100; |
| 1041 | } |
| 1042 | |
| 1043 | v4l2_dbg(2, debug, sd, "%s: %s gain: a = 0x%x, b = 0x%x, c = 0x%x\n", |
| 1044 | __func__, auto_gain ? "Auto" : "Manual", |
| 1045 | gain_a, gain_b, gain_c); |
| 1046 | |
| 1047 | gain_buf[0] = ((gain_man << 7) | (agc_mode_man << 6) | ((gain_a & 0x3f0) >> 4)); |
| 1048 | gain_buf[1] = (((gain_a & 0x00f) << 4) | ((gain_b & 0x3c0) >> 6)); |
| 1049 | gain_buf[2] = (((gain_b & 0x03f) << 2) | ((gain_c & 0x300) >> 8)); |
| 1050 | gain_buf[3] = ((gain_c & 0x0ff)); |
| 1051 | |
| 1052 | /* Registers must be written in this order with no i2c access in between */ |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1053 | if (adv_smbus_write_i2c_block_data(state, ADV76XX_PAGE_CP, |
Laurent Pinchart | 05cacb1 | 2014-01-30 16:32:21 -0300 | [diff] [blame] | 1054 | 0x73, 4, gain_buf)) |
Mats Randgaard | 5c6c634 | 2013-12-05 10:39:04 -0300 | [diff] [blame] | 1055 | v4l2_err(sd, "%s: i2c error writing to CP reg 0x73, 0x74, 0x75, 0x76\n", __func__); |
| 1056 | } |
| 1057 | |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1058 | static void set_rgb_quantization_range(struct v4l2_subdev *sd) |
| 1059 | { |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1060 | struct adv76xx_state *state = to_state(sd); |
Mats Randgaard | 5c6c634 | 2013-12-05 10:39:04 -0300 | [diff] [blame] | 1061 | bool rgb_output = io_read(sd, 0x02) & 0x02; |
| 1062 | bool hdmi_signal = hdmi_read(sd, 0x05) & 0x80; |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1063 | |
Mats Randgaard | 5c6c634 | 2013-12-05 10:39:04 -0300 | [diff] [blame] | 1064 | v4l2_dbg(2, debug, sd, "%s: RGB quantization range: %d, RGB out: %d, HDMI: %d\n", |
| 1065 | __func__, state->rgb_quantization_range, |
| 1066 | rgb_output, hdmi_signal); |
| 1067 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1068 | adv76xx_set_gain(sd, true, 0x0, 0x0, 0x0); |
| 1069 | adv76xx_set_offset(sd, true, 0x0, 0x0, 0x0); |
Mats Randgaard | 9833239 | 2013-12-05 10:05:58 -0300 | [diff] [blame] | 1070 | |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1071 | switch (state->rgb_quantization_range) { |
| 1072 | case V4L2_DV_RGB_RANGE_AUTO: |
Laurent Pinchart | c784b1e | 2014-01-29 10:08:58 -0300 | [diff] [blame] | 1073 | if (state->selected_input == ADV7604_PAD_VGA_RGB) { |
Mats Randgaard | 9833239 | 2013-12-05 10:05:58 -0300 | [diff] [blame] | 1074 | /* Receiving analog RGB signal |
| 1075 | * Set RGB full range (0-255) */ |
Laurent Pinchart | 22d97e5 | 2014-01-30 17:17:42 -0300 | [diff] [blame] | 1076 | io_write_clr_set(sd, 0x02, 0xf0, 0x10); |
Mats Randgaard | 9833239 | 2013-12-05 10:05:58 -0300 | [diff] [blame] | 1077 | break; |
| 1078 | } |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1079 | |
Laurent Pinchart | c784b1e | 2014-01-29 10:08:58 -0300 | [diff] [blame] | 1080 | if (state->selected_input == ADV7604_PAD_VGA_COMP) { |
Mats Randgaard | 9833239 | 2013-12-05 10:05:58 -0300 | [diff] [blame] | 1081 | /* Receiving analog YPbPr signal |
| 1082 | * Set automode */ |
Laurent Pinchart | 22d97e5 | 2014-01-30 17:17:42 -0300 | [diff] [blame] | 1083 | io_write_clr_set(sd, 0x02, 0xf0, 0xf0); |
Mats Randgaard | 9833239 | 2013-12-05 10:05:58 -0300 | [diff] [blame] | 1084 | break; |
| 1085 | } |
| 1086 | |
Mats Randgaard | 5c6c634 | 2013-12-05 10:39:04 -0300 | [diff] [blame] | 1087 | if (hdmi_signal) { |
Mats Randgaard | 9833239 | 2013-12-05 10:05:58 -0300 | [diff] [blame] | 1088 | /* Receiving HDMI signal |
| 1089 | * Set automode */ |
Laurent Pinchart | 22d97e5 | 2014-01-30 17:17:42 -0300 | [diff] [blame] | 1090 | io_write_clr_set(sd, 0x02, 0xf0, 0xf0); |
Mats Randgaard | 9833239 | 2013-12-05 10:05:58 -0300 | [diff] [blame] | 1091 | break; |
| 1092 | } |
| 1093 | |
| 1094 | /* Receiving DVI-D signal |
| 1095 | * ADV7604 selects RGB limited range regardless of |
| 1096 | * input format (CE/IT) in automatic mode */ |
Hans Verkuil | 680fee0 | 2015-03-20 14:05:05 -0300 | [diff] [blame] | 1097 | if (state->timings.bt.flags & V4L2_DV_FL_IS_CE_VIDEO) { |
Mats Randgaard | 9833239 | 2013-12-05 10:05:58 -0300 | [diff] [blame] | 1098 | /* RGB limited range (16-235) */ |
Laurent Pinchart | 22d97e5 | 2014-01-30 17:17:42 -0300 | [diff] [blame] | 1099 | io_write_clr_set(sd, 0x02, 0xf0, 0x00); |
Mats Randgaard | 9833239 | 2013-12-05 10:05:58 -0300 | [diff] [blame] | 1100 | } else { |
| 1101 | /* RGB full range (0-255) */ |
Laurent Pinchart | 22d97e5 | 2014-01-30 17:17:42 -0300 | [diff] [blame] | 1102 | io_write_clr_set(sd, 0x02, 0xf0, 0x10); |
Mats Randgaard | 5c6c634 | 2013-12-05 10:39:04 -0300 | [diff] [blame] | 1103 | |
| 1104 | if (is_digital_input(sd) && rgb_output) { |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1105 | adv76xx_set_offset(sd, false, 0x40, 0x40, 0x40); |
Mats Randgaard | 5c6c634 | 2013-12-05 10:39:04 -0300 | [diff] [blame] | 1106 | } else { |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1107 | adv76xx_set_gain(sd, false, 0xe0, 0xe0, 0xe0); |
| 1108 | adv76xx_set_offset(sd, false, 0x70, 0x70, 0x70); |
Mats Randgaard | 5c6c634 | 2013-12-05 10:39:04 -0300 | [diff] [blame] | 1109 | } |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1110 | } |
| 1111 | break; |
| 1112 | case V4L2_DV_RGB_RANGE_LIMITED: |
Laurent Pinchart | c784b1e | 2014-01-29 10:08:58 -0300 | [diff] [blame] | 1113 | if (state->selected_input == ADV7604_PAD_VGA_COMP) { |
Mats Randgaard | d261e84 | 2013-12-05 10:17:15 -0300 | [diff] [blame] | 1114 | /* YCrCb limited range (16-235) */ |
Laurent Pinchart | 22d97e5 | 2014-01-30 17:17:42 -0300 | [diff] [blame] | 1115 | io_write_clr_set(sd, 0x02, 0xf0, 0x20); |
Mats Randgaard | 5c6c634 | 2013-12-05 10:39:04 -0300 | [diff] [blame] | 1116 | break; |
Mats Randgaard | d261e84 | 2013-12-05 10:17:15 -0300 | [diff] [blame] | 1117 | } |
Mats Randgaard | 5c6c634 | 2013-12-05 10:39:04 -0300 | [diff] [blame] | 1118 | |
| 1119 | /* RGB limited range (16-235) */ |
Laurent Pinchart | 22d97e5 | 2014-01-30 17:17:42 -0300 | [diff] [blame] | 1120 | io_write_clr_set(sd, 0x02, 0xf0, 0x00); |
Mats Randgaard | 5c6c634 | 2013-12-05 10:39:04 -0300 | [diff] [blame] | 1121 | |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1122 | break; |
| 1123 | case V4L2_DV_RGB_RANGE_FULL: |
Laurent Pinchart | c784b1e | 2014-01-29 10:08:58 -0300 | [diff] [blame] | 1124 | if (state->selected_input == ADV7604_PAD_VGA_COMP) { |
Mats Randgaard | d261e84 | 2013-12-05 10:17:15 -0300 | [diff] [blame] | 1125 | /* YCrCb full range (0-255) */ |
Laurent Pinchart | 22d97e5 | 2014-01-30 17:17:42 -0300 | [diff] [blame] | 1126 | io_write_clr_set(sd, 0x02, 0xf0, 0x60); |
Mats Randgaard | 5c6c634 | 2013-12-05 10:39:04 -0300 | [diff] [blame] | 1127 | break; |
| 1128 | } |
| 1129 | |
| 1130 | /* RGB full range (0-255) */ |
Laurent Pinchart | 22d97e5 | 2014-01-30 17:17:42 -0300 | [diff] [blame] | 1131 | io_write_clr_set(sd, 0x02, 0xf0, 0x10); |
Mats Randgaard | 5c6c634 | 2013-12-05 10:39:04 -0300 | [diff] [blame] | 1132 | |
| 1133 | if (is_analog_input(sd) || hdmi_signal) |
| 1134 | break; |
| 1135 | |
| 1136 | /* Adjust gain/offset for DVI-D signals only */ |
| 1137 | if (rgb_output) { |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1138 | adv76xx_set_offset(sd, false, 0x40, 0x40, 0x40); |
Mats Randgaard | d261e84 | 2013-12-05 10:17:15 -0300 | [diff] [blame] | 1139 | } else { |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1140 | adv76xx_set_gain(sd, false, 0xe0, 0xe0, 0xe0); |
| 1141 | adv76xx_set_offset(sd, false, 0x70, 0x70, 0x70); |
Mats Randgaard | d261e84 | 2013-12-05 10:17:15 -0300 | [diff] [blame] | 1142 | } |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1143 | break; |
| 1144 | } |
| 1145 | } |
| 1146 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1147 | static int adv76xx_s_ctrl(struct v4l2_ctrl *ctrl) |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1148 | { |
Laurent Pinchart | c269887 | 2014-01-30 15:16:03 -0300 | [diff] [blame] | 1149 | struct v4l2_subdev *sd = |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1150 | &container_of(ctrl->handler, struct adv76xx_state, hdl)->sd; |
Laurent Pinchart | c269887 | 2014-01-30 15:16:03 -0300 | [diff] [blame] | 1151 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1152 | struct adv76xx_state *state = to_state(sd); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1153 | |
| 1154 | switch (ctrl->id) { |
| 1155 | case V4L2_CID_BRIGHTNESS: |
| 1156 | cp_write(sd, 0x3c, ctrl->val); |
| 1157 | return 0; |
| 1158 | case V4L2_CID_CONTRAST: |
| 1159 | cp_write(sd, 0x3a, ctrl->val); |
| 1160 | return 0; |
| 1161 | case V4L2_CID_SATURATION: |
| 1162 | cp_write(sd, 0x3b, ctrl->val); |
| 1163 | return 0; |
| 1164 | case V4L2_CID_HUE: |
| 1165 | cp_write(sd, 0x3d, ctrl->val); |
| 1166 | return 0; |
| 1167 | case V4L2_CID_DV_RX_RGB_RANGE: |
| 1168 | state->rgb_quantization_range = ctrl->val; |
| 1169 | set_rgb_quantization_range(sd); |
| 1170 | return 0; |
| 1171 | case V4L2_CID_ADV_RX_ANALOG_SAMPLING_PHASE: |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1172 | if (!adv76xx_has_afe(state)) |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 1173 | return -EINVAL; |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1174 | /* Set the analog sampling phase. This is needed to find the |
| 1175 | best sampling phase for analog video: an application or |
| 1176 | driver has to try a number of phases and analyze the picture |
| 1177 | quality before settling on the best performing phase. */ |
| 1178 | afe_write(sd, 0xc8, ctrl->val); |
| 1179 | return 0; |
| 1180 | case V4L2_CID_ADV_RX_FREE_RUN_COLOR_MANUAL: |
| 1181 | /* Use the default blue color for free running mode, |
| 1182 | or supply your own. */ |
Laurent Pinchart | 22d97e5 | 2014-01-30 17:17:42 -0300 | [diff] [blame] | 1183 | cp_write_clr_set(sd, 0xbf, 0x04, ctrl->val << 2); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1184 | return 0; |
| 1185 | case V4L2_CID_ADV_RX_FREE_RUN_COLOR: |
| 1186 | cp_write(sd, 0xc0, (ctrl->val & 0xff0000) >> 16); |
| 1187 | cp_write(sd, 0xc1, (ctrl->val & 0x00ff00) >> 8); |
| 1188 | cp_write(sd, 0xc2, (u8)(ctrl->val & 0x0000ff)); |
| 1189 | return 0; |
| 1190 | } |
| 1191 | return -EINVAL; |
| 1192 | } |
| 1193 | |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1194 | /* ----------------------------------------------------------------------- */ |
| 1195 | |
| 1196 | static inline bool no_power(struct v4l2_subdev *sd) |
| 1197 | { |
| 1198 | /* Entire chip or CP powered off */ |
| 1199 | return io_read(sd, 0x0c) & 0x24; |
| 1200 | } |
| 1201 | |
| 1202 | static inline bool no_signal_tmds(struct v4l2_subdev *sd) |
| 1203 | { |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1204 | struct adv76xx_state *state = to_state(sd); |
Mats Randgaard | 4a31a93 | 2013-12-10 09:45:00 -0300 | [diff] [blame] | 1205 | |
| 1206 | return !(io_read(sd, 0x6a) & (0x10 >> state->selected_input)); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1207 | } |
| 1208 | |
| 1209 | static inline bool no_lock_tmds(struct v4l2_subdev *sd) |
| 1210 | { |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1211 | struct adv76xx_state *state = to_state(sd); |
| 1212 | const struct adv76xx_chip_info *info = state->info; |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 1213 | |
| 1214 | return (io_read(sd, 0x6a) & info->tdms_lock_mask) != info->tdms_lock_mask; |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1215 | } |
| 1216 | |
Martin Bugge | bb88f32 | 2013-08-14 08:52:46 -0300 | [diff] [blame] | 1217 | static inline bool is_hdmi(struct v4l2_subdev *sd) |
| 1218 | { |
| 1219 | return hdmi_read(sd, 0x05) & 0x80; |
| 1220 | } |
| 1221 | |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1222 | static inline bool no_lock_sspd(struct v4l2_subdev *sd) |
| 1223 | { |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1224 | struct adv76xx_state *state = to_state(sd); |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 1225 | |
| 1226 | /* |
| 1227 | * Chips without a AFE don't expose registers for the SSPD, so just assume |
| 1228 | * that we have a lock. |
| 1229 | */ |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1230 | if (adv76xx_has_afe(state)) |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 1231 | return false; |
| 1232 | |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1233 | /* TODO channel 2 */ |
| 1234 | return ((cp_read(sd, 0xb5) & 0xd0) != 0xd0); |
| 1235 | } |
| 1236 | |
| 1237 | static inline bool no_lock_stdi(struct v4l2_subdev *sd) |
| 1238 | { |
| 1239 | /* TODO channel 2 */ |
| 1240 | return !(cp_read(sd, 0xb1) & 0x80); |
| 1241 | } |
| 1242 | |
| 1243 | static inline bool no_signal(struct v4l2_subdev *sd) |
| 1244 | { |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1245 | bool ret; |
| 1246 | |
| 1247 | ret = no_power(sd); |
| 1248 | |
| 1249 | ret |= no_lock_stdi(sd); |
| 1250 | ret |= no_lock_sspd(sd); |
| 1251 | |
Mats Randgaard | 4a31a93 | 2013-12-10 09:45:00 -0300 | [diff] [blame] | 1252 | if (is_digital_input(sd)) { |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1253 | ret |= no_lock_tmds(sd); |
| 1254 | ret |= no_signal_tmds(sd); |
| 1255 | } |
| 1256 | |
| 1257 | return ret; |
| 1258 | } |
| 1259 | |
| 1260 | static inline bool no_lock_cp(struct v4l2_subdev *sd) |
| 1261 | { |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1262 | struct adv76xx_state *state = to_state(sd); |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 1263 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1264 | if (!adv76xx_has_afe(state)) |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 1265 | return false; |
| 1266 | |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1267 | /* CP has detected a non standard number of lines on the incoming |
| 1268 | video compared to what it is configured to receive by s_dv_timings */ |
| 1269 | return io_read(sd, 0x12) & 0x01; |
| 1270 | } |
| 1271 | |
jean-michel.hautbois@vodalys.com | 5851462 | 2015-02-06 11:37:58 -0300 | [diff] [blame] | 1272 | static inline bool in_free_run(struct v4l2_subdev *sd) |
| 1273 | { |
| 1274 | return cp_read(sd, 0xff) & 0x10; |
| 1275 | } |
| 1276 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1277 | static int adv76xx_g_input_status(struct v4l2_subdev *sd, u32 *status) |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1278 | { |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1279 | *status = 0; |
| 1280 | *status |= no_power(sd) ? V4L2_IN_ST_NO_POWER : 0; |
| 1281 | *status |= no_signal(sd) ? V4L2_IN_ST_NO_SIGNAL : 0; |
jean-michel.hautbois@vodalys.com | 5851462 | 2015-02-06 11:37:58 -0300 | [diff] [blame] | 1282 | if (!in_free_run(sd) && no_lock_cp(sd)) |
| 1283 | *status |= is_digital_input(sd) ? |
| 1284 | V4L2_IN_ST_NO_SYNC : V4L2_IN_ST_NO_H_LOCK; |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1285 | |
| 1286 | v4l2_dbg(1, debug, sd, "%s: status = 0x%x\n", __func__, *status); |
| 1287 | |
| 1288 | return 0; |
| 1289 | } |
| 1290 | |
| 1291 | /* ----------------------------------------------------------------------- */ |
| 1292 | |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1293 | struct stdi_readback { |
| 1294 | u16 bl, lcf, lcvs; |
| 1295 | u8 hs_pol, vs_pol; |
| 1296 | bool interlaced; |
| 1297 | }; |
| 1298 | |
| 1299 | static int stdi2dv_timings(struct v4l2_subdev *sd, |
| 1300 | struct stdi_readback *stdi, |
| 1301 | struct v4l2_dv_timings *timings) |
| 1302 | { |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1303 | struct adv76xx_state *state = to_state(sd); |
| 1304 | u32 hfreq = (ADV76XX_FSC * 8) / stdi->bl; |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1305 | u32 pix_clk; |
| 1306 | int i; |
| 1307 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1308 | for (i = 0; adv76xx_timings[i].bt.height; i++) { |
| 1309 | if (vtotal(&adv76xx_timings[i].bt) != stdi->lcf + 1) |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1310 | continue; |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1311 | if (adv76xx_timings[i].bt.vsync != stdi->lcvs) |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1312 | continue; |
| 1313 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1314 | pix_clk = hfreq * htotal(&adv76xx_timings[i].bt); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1315 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1316 | if ((pix_clk < adv76xx_timings[i].bt.pixelclock + 1000000) && |
| 1317 | (pix_clk > adv76xx_timings[i].bt.pixelclock - 1000000)) { |
| 1318 | *timings = adv76xx_timings[i]; |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1319 | return 0; |
| 1320 | } |
| 1321 | } |
| 1322 | |
| 1323 | if (v4l2_detect_cvt(stdi->lcf + 1, hfreq, stdi->lcvs, |
| 1324 | (stdi->hs_pol == '+' ? V4L2_DV_HSYNC_POS_POL : 0) | |
| 1325 | (stdi->vs_pol == '+' ? V4L2_DV_VSYNC_POS_POL : 0), |
| 1326 | timings)) |
| 1327 | return 0; |
| 1328 | if (v4l2_detect_gtf(stdi->lcf + 1, hfreq, stdi->lcvs, |
| 1329 | (stdi->hs_pol == '+' ? V4L2_DV_HSYNC_POS_POL : 0) | |
| 1330 | (stdi->vs_pol == '+' ? V4L2_DV_VSYNC_POS_POL : 0), |
| 1331 | state->aspect_ratio, timings)) |
| 1332 | return 0; |
| 1333 | |
Hans Verkuil | ccbd5bc | 2012-10-16 10:02:05 -0300 | [diff] [blame] | 1334 | v4l2_dbg(2, debug, sd, |
| 1335 | "%s: No format candidate found for lcvs = %d, lcf=%d, bl = %d, %chsync, %cvsync\n", |
| 1336 | __func__, stdi->lcvs, stdi->lcf, stdi->bl, |
| 1337 | stdi->hs_pol, stdi->vs_pol); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1338 | return -1; |
| 1339 | } |
| 1340 | |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 1341 | |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1342 | static int read_stdi(struct v4l2_subdev *sd, struct stdi_readback *stdi) |
| 1343 | { |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1344 | struct adv76xx_state *state = to_state(sd); |
| 1345 | const struct adv76xx_chip_info *info = state->info; |
Laurent Pinchart | 4a2ccdd | 2014-01-08 20:26:55 -0300 | [diff] [blame] | 1346 | u8 polarity; |
| 1347 | |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1348 | if (no_lock_stdi(sd) || no_lock_sspd(sd)) { |
| 1349 | v4l2_dbg(2, debug, sd, "%s: STDI and/or SSPD not locked\n", __func__); |
| 1350 | return -1; |
| 1351 | } |
| 1352 | |
| 1353 | /* read STDI */ |
Laurent Pinchart | 51182a9 | 2014-01-08 19:30:37 -0300 | [diff] [blame] | 1354 | stdi->bl = cp_read16(sd, 0xb1, 0x3fff); |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 1355 | stdi->lcf = cp_read16(sd, info->lcf_reg, 0x7ff); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1356 | stdi->lcvs = cp_read(sd, 0xb3) >> 3; |
| 1357 | stdi->interlaced = io_read(sd, 0x12) & 0x10; |
| 1358 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1359 | if (adv76xx_has_afe(state)) { |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 1360 | /* read SSPD */ |
| 1361 | polarity = cp_read(sd, 0xb5); |
| 1362 | if ((polarity & 0x03) == 0x01) { |
| 1363 | stdi->hs_pol = polarity & 0x10 |
| 1364 | ? (polarity & 0x08 ? '+' : '-') : 'x'; |
| 1365 | stdi->vs_pol = polarity & 0x40 |
| 1366 | ? (polarity & 0x20 ? '+' : '-') : 'x'; |
| 1367 | } else { |
| 1368 | stdi->hs_pol = 'x'; |
| 1369 | stdi->vs_pol = 'x'; |
| 1370 | } |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1371 | } else { |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 1372 | polarity = hdmi_read(sd, 0x05); |
| 1373 | stdi->hs_pol = polarity & 0x20 ? '+' : '-'; |
| 1374 | stdi->vs_pol = polarity & 0x10 ? '+' : '-'; |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1375 | } |
| 1376 | |
| 1377 | if (no_lock_stdi(sd) || no_lock_sspd(sd)) { |
| 1378 | v4l2_dbg(2, debug, sd, |
| 1379 | "%s: signal lost during readout of STDI/SSPD\n", __func__); |
| 1380 | return -1; |
| 1381 | } |
| 1382 | |
| 1383 | if (stdi->lcf < 239 || stdi->bl < 8 || stdi->bl == 0x3fff) { |
| 1384 | v4l2_dbg(2, debug, sd, "%s: invalid signal\n", __func__); |
| 1385 | memset(stdi, 0, sizeof(struct stdi_readback)); |
| 1386 | return -1; |
| 1387 | } |
| 1388 | |
| 1389 | v4l2_dbg(2, debug, sd, |
| 1390 | "%s: lcf (frame height - 1) = %d, bl = %d, lcvs (vsync) = %d, %chsync, %cvsync, %s\n", |
| 1391 | __func__, stdi->lcf, stdi->bl, stdi->lcvs, |
| 1392 | stdi->hs_pol, stdi->vs_pol, |
| 1393 | stdi->interlaced ? "interlaced" : "progressive"); |
| 1394 | |
| 1395 | return 0; |
| 1396 | } |
| 1397 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1398 | static int adv76xx_enum_dv_timings(struct v4l2_subdev *sd, |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1399 | struct v4l2_enum_dv_timings *timings) |
| 1400 | { |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1401 | struct adv76xx_state *state = to_state(sd); |
Laurent Pinchart | afec559 | 2014-01-29 10:09:41 -0300 | [diff] [blame] | 1402 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1403 | if (timings->index >= ARRAY_SIZE(adv76xx_timings) - 1) |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1404 | return -EINVAL; |
Laurent Pinchart | afec559 | 2014-01-29 10:09:41 -0300 | [diff] [blame] | 1405 | |
| 1406 | if (timings->pad >= state->source_pad) |
| 1407 | return -EINVAL; |
| 1408 | |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1409 | memset(timings->reserved, 0, sizeof(timings->reserved)); |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1410 | timings->timings = adv76xx_timings[timings->index]; |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1411 | return 0; |
| 1412 | } |
| 1413 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1414 | static int adv76xx_dv_timings_cap(struct v4l2_subdev *sd, |
Laurent Pinchart | 7515e09 | 2014-01-31 08:51:18 -0300 | [diff] [blame] | 1415 | struct v4l2_dv_timings_cap *cap) |
Laurent Pinchart | afec559 | 2014-01-29 10:09:41 -0300 | [diff] [blame] | 1416 | { |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1417 | struct adv76xx_state *state = to_state(sd); |
Laurent Pinchart | 7515e09 | 2014-01-31 08:51:18 -0300 | [diff] [blame] | 1418 | |
| 1419 | if (cap->pad >= state->source_pad) |
| 1420 | return -EINVAL; |
| 1421 | |
Laurent Pinchart | afec559 | 2014-01-29 10:09:41 -0300 | [diff] [blame] | 1422 | cap->type = V4L2_DV_BT_656_1120; |
| 1423 | cap->bt.max_width = 1920; |
| 1424 | cap->bt.max_height = 1200; |
| 1425 | cap->bt.min_pixelclock = 25000000; |
| 1426 | |
Laurent Pinchart | 7515e09 | 2014-01-31 08:51:18 -0300 | [diff] [blame] | 1427 | switch (cap->pad) { |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1428 | case ADV76XX_PAD_HDMI_PORT_A: |
Laurent Pinchart | afec559 | 2014-01-29 10:09:41 -0300 | [diff] [blame] | 1429 | case ADV7604_PAD_HDMI_PORT_B: |
| 1430 | case ADV7604_PAD_HDMI_PORT_C: |
| 1431 | case ADV7604_PAD_HDMI_PORT_D: |
| 1432 | cap->bt.max_pixelclock = 225000000; |
| 1433 | break; |
| 1434 | case ADV7604_PAD_VGA_RGB: |
| 1435 | case ADV7604_PAD_VGA_COMP: |
| 1436 | default: |
| 1437 | cap->bt.max_pixelclock = 170000000; |
| 1438 | break; |
| 1439 | } |
| 1440 | |
| 1441 | cap->bt.standards = V4L2_DV_BT_STD_CEA861 | V4L2_DV_BT_STD_DMT | |
| 1442 | V4L2_DV_BT_STD_GTF | V4L2_DV_BT_STD_CVT; |
| 1443 | cap->bt.capabilities = V4L2_DV_BT_CAP_PROGRESSIVE | |
| 1444 | V4L2_DV_BT_CAP_REDUCED_BLANKING | V4L2_DV_BT_CAP_CUSTOM; |
| 1445 | return 0; |
| 1446 | } |
| 1447 | |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1448 | /* Fill the optional fields .standards and .flags in struct v4l2_dv_timings |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1449 | if the format is listed in adv76xx_timings[] */ |
| 1450 | static void adv76xx_fill_optional_dv_timings_fields(struct v4l2_subdev *sd, |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1451 | struct v4l2_dv_timings *timings) |
| 1452 | { |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1453 | int i; |
| 1454 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1455 | for (i = 0; adv76xx_timings[i].bt.width; i++) { |
| 1456 | if (v4l2_match_dv_timings(timings, &adv76xx_timings[i], |
Mats Randgaard | 4a31a93 | 2013-12-10 09:45:00 -0300 | [diff] [blame] | 1457 | is_digital_input(sd) ? 250000 : 1000000)) { |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1458 | *timings = adv76xx_timings[i]; |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1459 | break; |
| 1460 | } |
| 1461 | } |
| 1462 | } |
| 1463 | |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 1464 | static unsigned int adv7604_read_hdmi_pixelclock(struct v4l2_subdev *sd) |
| 1465 | { |
| 1466 | unsigned int freq; |
| 1467 | int a, b; |
| 1468 | |
| 1469 | a = hdmi_read(sd, 0x06); |
| 1470 | b = hdmi_read(sd, 0x3b); |
| 1471 | if (a < 0 || b < 0) |
| 1472 | return 0; |
| 1473 | freq = a * 1000000 + ((b & 0x30) >> 4) * 250000; |
| 1474 | |
| 1475 | if (is_hdmi(sd)) { |
| 1476 | /* adjust for deep color mode */ |
| 1477 | unsigned bits_per_channel = ((hdmi_read(sd, 0x0b) & 0x60) >> 4) + 8; |
| 1478 | |
| 1479 | freq = freq * 8 / bits_per_channel; |
| 1480 | } |
| 1481 | |
| 1482 | return freq; |
| 1483 | } |
| 1484 | |
| 1485 | static unsigned int adv7611_read_hdmi_pixelclock(struct v4l2_subdev *sd) |
| 1486 | { |
| 1487 | int a, b; |
| 1488 | |
| 1489 | a = hdmi_read(sd, 0x51); |
| 1490 | b = hdmi_read(sd, 0x52); |
| 1491 | if (a < 0 || b < 0) |
| 1492 | return 0; |
| 1493 | return ((a << 1) | (b >> 7)) * 1000000 + (b & 0x7f) * 1000000 / 128; |
| 1494 | } |
| 1495 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1496 | static int adv76xx_query_dv_timings(struct v4l2_subdev *sd, |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1497 | struct v4l2_dv_timings *timings) |
| 1498 | { |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1499 | struct adv76xx_state *state = to_state(sd); |
| 1500 | const struct adv76xx_chip_info *info = state->info; |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1501 | struct v4l2_bt_timings *bt = &timings->bt; |
| 1502 | struct stdi_readback stdi; |
| 1503 | |
| 1504 | if (!timings) |
| 1505 | return -EINVAL; |
| 1506 | |
| 1507 | memset(timings, 0, sizeof(struct v4l2_dv_timings)); |
| 1508 | |
| 1509 | if (no_signal(sd)) { |
Martin Bugge | 1e0b915 | 2013-12-05 10:34:46 -0300 | [diff] [blame] | 1510 | state->restart_stdi_once = true; |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1511 | v4l2_dbg(1, debug, sd, "%s: no valid signal\n", __func__); |
| 1512 | return -ENOLINK; |
| 1513 | } |
| 1514 | |
| 1515 | /* read STDI */ |
| 1516 | if (read_stdi(sd, &stdi)) { |
| 1517 | v4l2_dbg(1, debug, sd, "%s: STDI/SSPD not locked\n", __func__); |
| 1518 | return -ENOLINK; |
| 1519 | } |
| 1520 | bt->interlaced = stdi.interlaced ? |
| 1521 | V4L2_DV_INTERLACED : V4L2_DV_PROGRESSIVE; |
| 1522 | |
Mats Randgaard | 4a31a93 | 2013-12-10 09:45:00 -0300 | [diff] [blame] | 1523 | if (is_digital_input(sd)) { |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1524 | timings->type = V4L2_DV_BT_656_1120; |
| 1525 | |
jean-michel.hautbois@vodalys.com | 5380baa | 2015-04-09 05:25:46 -0300 | [diff] [blame] | 1526 | bt->width = hdmi_read16(sd, 0x07, info->linewidth_mask); |
| 1527 | bt->height = hdmi_read16(sd, 0x09, info->field0_height_mask); |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 1528 | bt->pixelclock = info->read_hdmi_pixelclock(sd); |
jean-michel.hautbois@vodalys.com | 5380baa | 2015-04-09 05:25:46 -0300 | [diff] [blame] | 1529 | bt->hfrontporch = hdmi_read16(sd, 0x20, info->hfrontporch_mask); |
| 1530 | bt->hsync = hdmi_read16(sd, 0x22, info->hsync_mask); |
| 1531 | bt->hbackporch = hdmi_read16(sd, 0x24, info->hbackporch_mask); |
| 1532 | bt->vfrontporch = hdmi_read16(sd, 0x2a, |
| 1533 | info->field0_vfrontporch_mask) / 2; |
| 1534 | bt->vsync = hdmi_read16(sd, 0x2e, info->field0_vsync_mask) / 2; |
| 1535 | bt->vbackporch = hdmi_read16(sd, 0x32, |
| 1536 | info->field0_vbackporch_mask) / 2; |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1537 | bt->polarities = ((hdmi_read(sd, 0x05) & 0x10) ? V4L2_DV_VSYNC_POS_POL : 0) | |
| 1538 | ((hdmi_read(sd, 0x05) & 0x20) ? V4L2_DV_HSYNC_POS_POL : 0); |
| 1539 | if (bt->interlaced == V4L2_DV_INTERLACED) { |
jean-michel.hautbois@vodalys.com | 5380baa | 2015-04-09 05:25:46 -0300 | [diff] [blame] | 1540 | bt->height += hdmi_read16(sd, 0x0b, |
| 1541 | info->field1_height_mask); |
| 1542 | bt->il_vfrontporch = hdmi_read16(sd, 0x2c, |
| 1543 | info->field1_vfrontporch_mask) / 2; |
| 1544 | bt->il_vsync = hdmi_read16(sd, 0x30, |
| 1545 | info->field1_vsync_mask) / 2; |
| 1546 | bt->il_vbackporch = hdmi_read16(sd, 0x34, |
| 1547 | info->field1_vbackporch_mask) / 2; |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1548 | } |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1549 | adv76xx_fill_optional_dv_timings_fields(sd, timings); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1550 | } else { |
| 1551 | /* find format |
Hans Verkuil | 8093964 | 2012-10-16 05:46:21 -0300 | [diff] [blame] | 1552 | * Since LCVS values are inaccurate [REF_03, p. 275-276], |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1553 | * stdi2dv_timings() is called with lcvs +-1 if the first attempt fails. |
| 1554 | */ |
| 1555 | if (!stdi2dv_timings(sd, &stdi, timings)) |
| 1556 | goto found; |
| 1557 | stdi.lcvs += 1; |
| 1558 | v4l2_dbg(1, debug, sd, "%s: lcvs + 1 = %d\n", __func__, stdi.lcvs); |
| 1559 | if (!stdi2dv_timings(sd, &stdi, timings)) |
| 1560 | goto found; |
| 1561 | stdi.lcvs -= 2; |
| 1562 | v4l2_dbg(1, debug, sd, "%s: lcvs - 1 = %d\n", __func__, stdi.lcvs); |
| 1563 | if (stdi2dv_timings(sd, &stdi, timings)) { |
Hans Verkuil | cf9afb1 | 2012-10-16 10:12:55 -0300 | [diff] [blame] | 1564 | /* |
| 1565 | * The STDI block may measure wrong values, especially |
| 1566 | * for lcvs and lcf. If the driver can not find any |
| 1567 | * valid timing, the STDI block is restarted to measure |
| 1568 | * the video timings again. The function will return an |
| 1569 | * error, but the restart of STDI will generate a new |
| 1570 | * STDI interrupt and the format detection process will |
| 1571 | * restart. |
| 1572 | */ |
| 1573 | if (state->restart_stdi_once) { |
| 1574 | v4l2_dbg(1, debug, sd, "%s: restart STDI\n", __func__); |
| 1575 | /* TODO restart STDI for Sync Channel 2 */ |
| 1576 | /* enter one-shot mode */ |
Laurent Pinchart | 22d97e5 | 2014-01-30 17:17:42 -0300 | [diff] [blame] | 1577 | cp_write_clr_set(sd, 0x86, 0x06, 0x00); |
Hans Verkuil | cf9afb1 | 2012-10-16 10:12:55 -0300 | [diff] [blame] | 1578 | /* trigger STDI restart */ |
Laurent Pinchart | 22d97e5 | 2014-01-30 17:17:42 -0300 | [diff] [blame] | 1579 | cp_write_clr_set(sd, 0x86, 0x06, 0x04); |
Hans Verkuil | cf9afb1 | 2012-10-16 10:12:55 -0300 | [diff] [blame] | 1580 | /* reset to continuous mode */ |
Laurent Pinchart | 22d97e5 | 2014-01-30 17:17:42 -0300 | [diff] [blame] | 1581 | cp_write_clr_set(sd, 0x86, 0x06, 0x02); |
Hans Verkuil | cf9afb1 | 2012-10-16 10:12:55 -0300 | [diff] [blame] | 1582 | state->restart_stdi_once = false; |
| 1583 | return -ENOLINK; |
| 1584 | } |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1585 | v4l2_dbg(1, debug, sd, "%s: format not supported\n", __func__); |
| 1586 | return -ERANGE; |
| 1587 | } |
Hans Verkuil | cf9afb1 | 2012-10-16 10:12:55 -0300 | [diff] [blame] | 1588 | state->restart_stdi_once = true; |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1589 | } |
| 1590 | found: |
| 1591 | |
| 1592 | if (no_signal(sd)) { |
| 1593 | v4l2_dbg(1, debug, sd, "%s: signal lost during readout\n", __func__); |
| 1594 | memset(timings, 0, sizeof(struct v4l2_dv_timings)); |
| 1595 | return -ENOLINK; |
| 1596 | } |
| 1597 | |
Mats Randgaard | 4a31a93 | 2013-12-10 09:45:00 -0300 | [diff] [blame] | 1598 | if ((is_analog_input(sd) && bt->pixelclock > 170000000) || |
| 1599 | (is_digital_input(sd) && bt->pixelclock > 225000000)) { |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1600 | v4l2_dbg(1, debug, sd, "%s: pixelclock out of range %d\n", |
| 1601 | __func__, (u32)bt->pixelclock); |
| 1602 | return -ERANGE; |
| 1603 | } |
| 1604 | |
| 1605 | if (debug > 1) |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1606 | v4l2_print_dv_timings(sd->name, "adv76xx_query_dv_timings: ", |
Hans Verkuil | 11d034c | 2013-08-15 08:05:59 -0300 | [diff] [blame] | 1607 | timings, true); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1608 | |
| 1609 | return 0; |
| 1610 | } |
| 1611 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1612 | static int adv76xx_s_dv_timings(struct v4l2_subdev *sd, |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1613 | struct v4l2_dv_timings *timings) |
| 1614 | { |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1615 | struct adv76xx_state *state = to_state(sd); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1616 | struct v4l2_bt_timings *bt; |
Hans Verkuil | ccbd5bc | 2012-10-16 10:02:05 -0300 | [diff] [blame] | 1617 | int err; |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1618 | |
| 1619 | if (!timings) |
| 1620 | return -EINVAL; |
| 1621 | |
Mats Randgaard | d48eb48 | 2013-12-12 10:13:35 -0300 | [diff] [blame] | 1622 | if (v4l2_match_dv_timings(&state->timings, timings, 0)) { |
| 1623 | v4l2_dbg(1, debug, sd, "%s: no change\n", __func__); |
| 1624 | return 0; |
| 1625 | } |
| 1626 | |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1627 | bt = &timings->bt; |
| 1628 | |
Mats Randgaard | 4a31a93 | 2013-12-10 09:45:00 -0300 | [diff] [blame] | 1629 | if ((is_analog_input(sd) && bt->pixelclock > 170000000) || |
| 1630 | (is_digital_input(sd) && bt->pixelclock > 225000000)) { |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1631 | v4l2_dbg(1, debug, sd, "%s: pixelclock out of range %d\n", |
| 1632 | __func__, (u32)bt->pixelclock); |
| 1633 | return -ERANGE; |
| 1634 | } |
Hans Verkuil | ccbd5bc | 2012-10-16 10:02:05 -0300 | [diff] [blame] | 1635 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1636 | adv76xx_fill_optional_dv_timings_fields(sd, timings); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1637 | |
| 1638 | state->timings = *timings; |
| 1639 | |
Laurent Pinchart | 22d97e5 | 2014-01-30 17:17:42 -0300 | [diff] [blame] | 1640 | cp_write_clr_set(sd, 0x91, 0x40, bt->interlaced ? 0x40 : 0x00); |
Hans Verkuil | ccbd5bc | 2012-10-16 10:02:05 -0300 | [diff] [blame] | 1641 | |
| 1642 | /* Use prim_mode and vid_std when available */ |
| 1643 | err = configure_predefined_video_timings(sd, timings); |
| 1644 | if (err) { |
| 1645 | /* custom settings when the video format |
| 1646 | does not have prim_mode/vid_std */ |
| 1647 | configure_custom_video_timings(sd, bt); |
| 1648 | } |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1649 | |
| 1650 | set_rgb_quantization_range(sd); |
| 1651 | |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1652 | if (debug > 1) |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1653 | v4l2_print_dv_timings(sd->name, "adv76xx_s_dv_timings: ", |
Hans Verkuil | 11d034c | 2013-08-15 08:05:59 -0300 | [diff] [blame] | 1654 | timings, true); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1655 | return 0; |
| 1656 | } |
| 1657 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1658 | static int adv76xx_g_dv_timings(struct v4l2_subdev *sd, |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1659 | struct v4l2_dv_timings *timings) |
| 1660 | { |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1661 | struct adv76xx_state *state = to_state(sd); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1662 | |
| 1663 | *timings = state->timings; |
| 1664 | return 0; |
| 1665 | } |
| 1666 | |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 1667 | static void adv7604_set_termination(struct v4l2_subdev *sd, bool enable) |
| 1668 | { |
| 1669 | hdmi_write(sd, 0x01, enable ? 0x00 : 0x78); |
| 1670 | } |
| 1671 | |
| 1672 | static void adv7611_set_termination(struct v4l2_subdev *sd, bool enable) |
| 1673 | { |
| 1674 | hdmi_write(sd, 0x83, enable ? 0xfe : 0xff); |
| 1675 | } |
| 1676 | |
Hans Verkuil | 6b0d5d3 | 2012-10-16 06:40:45 -0300 | [diff] [blame] | 1677 | static void enable_input(struct v4l2_subdev *sd) |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1678 | { |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1679 | struct adv76xx_state *state = to_state(sd); |
Hans Verkuil | 6b0d5d3 | 2012-10-16 06:40:45 -0300 | [diff] [blame] | 1680 | |
Mats Randgaard | 4a31a93 | 2013-12-10 09:45:00 -0300 | [diff] [blame] | 1681 | if (is_analog_input(sd)) { |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1682 | io_write(sd, 0x15, 0xb0); /* Disable Tristate of Pins (no audio) */ |
Mats Randgaard | 4a31a93 | 2013-12-10 09:45:00 -0300 | [diff] [blame] | 1683 | } else if (is_digital_input(sd)) { |
Laurent Pinchart | 22d97e5 | 2014-01-30 17:17:42 -0300 | [diff] [blame] | 1684 | hdmi_write_clr_set(sd, 0x00, 0x03, state->selected_input); |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 1685 | state->info->set_termination(sd, true); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1686 | io_write(sd, 0x15, 0xa0); /* Disable Tristate of Pins */ |
Laurent Pinchart | 22d97e5 | 2014-01-30 17:17:42 -0300 | [diff] [blame] | 1687 | hdmi_write_clr_set(sd, 0x1a, 0x10, 0x00); /* Unmute audio */ |
Mats Randgaard | 4a31a93 | 2013-12-10 09:45:00 -0300 | [diff] [blame] | 1688 | } else { |
| 1689 | v4l2_dbg(2, debug, sd, "%s: Unknown port %d selected\n", |
| 1690 | __func__, state->selected_input); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1691 | } |
| 1692 | } |
| 1693 | |
| 1694 | static void disable_input(struct v4l2_subdev *sd) |
| 1695 | { |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1696 | struct adv76xx_state *state = to_state(sd); |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 1697 | |
Laurent Pinchart | 22d97e5 | 2014-01-30 17:17:42 -0300 | [diff] [blame] | 1698 | hdmi_write_clr_set(sd, 0x1a, 0x10, 0x10); /* Mute audio */ |
Mats Randgaard | 5474b98 | 2013-12-05 10:33:41 -0300 | [diff] [blame] | 1699 | msleep(16); /* 512 samples with >= 32 kHz sample rate [REF_03, c. 7.16.10] */ |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1700 | io_write(sd, 0x15, 0xbe); /* Tristate all outputs from video core */ |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 1701 | state->info->set_termination(sd, false); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1702 | } |
| 1703 | |
Hans Verkuil | 6b0d5d3 | 2012-10-16 06:40:45 -0300 | [diff] [blame] | 1704 | static void select_input(struct v4l2_subdev *sd) |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1705 | { |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1706 | struct adv76xx_state *state = to_state(sd); |
| 1707 | const struct adv76xx_chip_info *info = state->info; |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1708 | |
Mats Randgaard | 4a31a93 | 2013-12-10 09:45:00 -0300 | [diff] [blame] | 1709 | if (is_analog_input(sd)) { |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1710 | adv76xx_write_reg_seq(sd, info->recommended_settings[0]); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1711 | |
| 1712 | afe_write(sd, 0x00, 0x08); /* power up ADC */ |
| 1713 | afe_write(sd, 0x01, 0x06); /* power up Analog Front End */ |
| 1714 | afe_write(sd, 0xc8, 0x00); /* phase control */ |
Mats Randgaard | 4a31a93 | 2013-12-10 09:45:00 -0300 | [diff] [blame] | 1715 | } else if (is_digital_input(sd)) { |
| 1716 | hdmi_write(sd, 0x00, state->selected_input & 0x03); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1717 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1718 | adv76xx_write_reg_seq(sd, info->recommended_settings[1]); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1719 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1720 | if (adv76xx_has_afe(state)) { |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 1721 | afe_write(sd, 0x00, 0xff); /* power down ADC */ |
| 1722 | afe_write(sd, 0x01, 0xfe); /* power down Analog Front End */ |
| 1723 | afe_write(sd, 0xc8, 0x40); /* phase control */ |
| 1724 | } |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1725 | |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1726 | cp_write(sd, 0x3e, 0x00); /* CP core pre-gain control */ |
| 1727 | cp_write(sd, 0xc3, 0x39); /* CP coast control. Graphics mode */ |
| 1728 | cp_write(sd, 0x40, 0x80); /* CP core pre-gain control. Graphics mode */ |
Mats Randgaard | 4a31a93 | 2013-12-10 09:45:00 -0300 | [diff] [blame] | 1729 | } else { |
| 1730 | v4l2_dbg(2, debug, sd, "%s: Unknown port %d selected\n", |
| 1731 | __func__, state->selected_input); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1732 | } |
| 1733 | } |
| 1734 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1735 | static int adv76xx_s_routing(struct v4l2_subdev *sd, |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1736 | u32 input, u32 output, u32 config) |
| 1737 | { |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1738 | struct adv76xx_state *state = to_state(sd); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1739 | |
Mats Randgaard | ff4f80f | 2013-12-05 10:24:05 -0300 | [diff] [blame] | 1740 | v4l2_dbg(2, debug, sd, "%s: input %d, selected input %d", |
| 1741 | __func__, input, state->selected_input); |
| 1742 | |
| 1743 | if (input == state->selected_input) |
| 1744 | return 0; |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1745 | |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 1746 | if (input > state->info->max_port) |
| 1747 | return -EINVAL; |
| 1748 | |
Mats Randgaard | 4a31a93 | 2013-12-10 09:45:00 -0300 | [diff] [blame] | 1749 | state->selected_input = input; |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1750 | |
| 1751 | disable_input(sd); |
Hans Verkuil | 6b0d5d3 | 2012-10-16 06:40:45 -0300 | [diff] [blame] | 1752 | select_input(sd); |
Hans Verkuil | 6b0d5d3 | 2012-10-16 06:40:45 -0300 | [diff] [blame] | 1753 | enable_input(sd); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1754 | |
Hans Verkuil | 4851983 | 2015-05-07 10:37:57 -0300 | [diff] [blame^] | 1755 | v4l2_subdev_notify(sd, V4L2_DEVICE_NOTIFY_EVENT, |
| 1756 | (void *)&adv76xx_ev_fmt); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1757 | return 0; |
| 1758 | } |
| 1759 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1760 | static int adv76xx_enum_mbus_code(struct v4l2_subdev *sd, |
Hans Verkuil | f723413 | 2015-03-04 01:47:54 -0800 | [diff] [blame] | 1761 | struct v4l2_subdev_pad_config *cfg, |
Laurent Pinchart | 539b33b | 2014-01-26 18:42:37 -0300 | [diff] [blame] | 1762 | struct v4l2_subdev_mbus_code_enum *code) |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1763 | { |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1764 | struct adv76xx_state *state = to_state(sd); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1765 | |
Laurent Pinchart | 539b33b | 2014-01-26 18:42:37 -0300 | [diff] [blame] | 1766 | if (code->index >= state->info->nformats) |
| 1767 | return -EINVAL; |
| 1768 | |
| 1769 | code->code = state->info->formats[code->index].code; |
| 1770 | |
| 1771 | return 0; |
| 1772 | } |
| 1773 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1774 | static void adv76xx_fill_format(struct adv76xx_state *state, |
Laurent Pinchart | 539b33b | 2014-01-26 18:42:37 -0300 | [diff] [blame] | 1775 | struct v4l2_mbus_framefmt *format) |
| 1776 | { |
| 1777 | memset(format, 0, sizeof(*format)); |
| 1778 | |
| 1779 | format->width = state->timings.bt.width; |
| 1780 | format->height = state->timings.bt.height; |
| 1781 | format->field = V4L2_FIELD_NONE; |
Hans Verkuil | 680fee0 | 2015-03-20 14:05:05 -0300 | [diff] [blame] | 1782 | format->colorspace = V4L2_COLORSPACE_SRGB; |
Laurent Pinchart | 539b33b | 2014-01-26 18:42:37 -0300 | [diff] [blame] | 1783 | |
Hans Verkuil | 680fee0 | 2015-03-20 14:05:05 -0300 | [diff] [blame] | 1784 | if (state->timings.bt.flags & V4L2_DV_FL_IS_CE_VIDEO) |
Laurent Pinchart | 539b33b | 2014-01-26 18:42:37 -0300 | [diff] [blame] | 1785 | format->colorspace = (state->timings.bt.height <= 576) ? |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1786 | V4L2_COLORSPACE_SMPTE170M : V4L2_COLORSPACE_REC709; |
Laurent Pinchart | 539b33b | 2014-01-26 18:42:37 -0300 | [diff] [blame] | 1787 | } |
| 1788 | |
| 1789 | /* |
| 1790 | * Compute the op_ch_sel value required to obtain on the bus the component order |
| 1791 | * corresponding to the selected format taking into account bus reordering |
| 1792 | * applied by the board at the output of the device. |
| 1793 | * |
| 1794 | * The following table gives the op_ch_value from the format component order |
| 1795 | * (expressed as op_ch_sel value in column) and the bus reordering (expressed as |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1796 | * adv76xx_bus_order value in row). |
Laurent Pinchart | 539b33b | 2014-01-26 18:42:37 -0300 | [diff] [blame] | 1797 | * |
| 1798 | * | GBR(0) GRB(1) BGR(2) RGB(3) BRG(4) RBG(5) |
| 1799 | * ----------+------------------------------------------------- |
| 1800 | * RGB (NOP) | GBR GRB BGR RGB BRG RBG |
| 1801 | * GRB (1-2) | BGR RGB GBR GRB RBG BRG |
| 1802 | * RBG (2-3) | GRB GBR BRG RBG BGR RGB |
| 1803 | * BGR (1-3) | RBG BRG RGB BGR GRB GBR |
| 1804 | * BRG (ROR) | BRG RBG GRB GBR RGB BGR |
| 1805 | * GBR (ROL) | RGB BGR RBG BRG GBR GRB |
| 1806 | */ |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1807 | static unsigned int adv76xx_op_ch_sel(struct adv76xx_state *state) |
Laurent Pinchart | 539b33b | 2014-01-26 18:42:37 -0300 | [diff] [blame] | 1808 | { |
| 1809 | #define _SEL(a,b,c,d,e,f) { \ |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1810 | ADV76XX_OP_CH_SEL_##a, ADV76XX_OP_CH_SEL_##b, ADV76XX_OP_CH_SEL_##c, \ |
| 1811 | ADV76XX_OP_CH_SEL_##d, ADV76XX_OP_CH_SEL_##e, ADV76XX_OP_CH_SEL_##f } |
Laurent Pinchart | 539b33b | 2014-01-26 18:42:37 -0300 | [diff] [blame] | 1812 | #define _BUS(x) [ADV7604_BUS_ORDER_##x] |
| 1813 | |
| 1814 | static const unsigned int op_ch_sel[6][6] = { |
| 1815 | _BUS(RGB) /* NOP */ = _SEL(GBR, GRB, BGR, RGB, BRG, RBG), |
| 1816 | _BUS(GRB) /* 1-2 */ = _SEL(BGR, RGB, GBR, GRB, RBG, BRG), |
| 1817 | _BUS(RBG) /* 2-3 */ = _SEL(GRB, GBR, BRG, RBG, BGR, RGB), |
| 1818 | _BUS(BGR) /* 1-3 */ = _SEL(RBG, BRG, RGB, BGR, GRB, GBR), |
| 1819 | _BUS(BRG) /* ROR */ = _SEL(BRG, RBG, GRB, GBR, RGB, BGR), |
| 1820 | _BUS(GBR) /* ROL */ = _SEL(RGB, BGR, RBG, BRG, GBR, GRB), |
| 1821 | }; |
| 1822 | |
| 1823 | return op_ch_sel[state->pdata.bus_order][state->format->op_ch_sel >> 5]; |
| 1824 | } |
| 1825 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1826 | static void adv76xx_setup_format(struct adv76xx_state *state) |
Laurent Pinchart | 539b33b | 2014-01-26 18:42:37 -0300 | [diff] [blame] | 1827 | { |
| 1828 | struct v4l2_subdev *sd = &state->sd; |
| 1829 | |
Laurent Pinchart | 22d97e5 | 2014-01-30 17:17:42 -0300 | [diff] [blame] | 1830 | io_write_clr_set(sd, 0x02, 0x02, |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1831 | state->format->rgb_out ? ADV76XX_RGB_OUT : 0); |
Laurent Pinchart | 539b33b | 2014-01-26 18:42:37 -0300 | [diff] [blame] | 1832 | io_write(sd, 0x03, state->format->op_format_sel | |
| 1833 | state->pdata.op_format_mode_sel); |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1834 | io_write_clr_set(sd, 0x04, 0xe0, adv76xx_op_ch_sel(state)); |
Laurent Pinchart | 22d97e5 | 2014-01-30 17:17:42 -0300 | [diff] [blame] | 1835 | io_write_clr_set(sd, 0x05, 0x01, |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1836 | state->format->swap_cb_cr ? ADV76XX_OP_SWAP_CB_CR : 0); |
Laurent Pinchart | 539b33b | 2014-01-26 18:42:37 -0300 | [diff] [blame] | 1837 | } |
| 1838 | |
Hans Verkuil | f723413 | 2015-03-04 01:47:54 -0800 | [diff] [blame] | 1839 | static int adv76xx_get_format(struct v4l2_subdev *sd, |
| 1840 | struct v4l2_subdev_pad_config *cfg, |
Laurent Pinchart | 539b33b | 2014-01-26 18:42:37 -0300 | [diff] [blame] | 1841 | struct v4l2_subdev_format *format) |
| 1842 | { |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1843 | struct adv76xx_state *state = to_state(sd); |
Laurent Pinchart | 539b33b | 2014-01-26 18:42:37 -0300 | [diff] [blame] | 1844 | |
| 1845 | if (format->pad != state->source_pad) |
| 1846 | return -EINVAL; |
| 1847 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1848 | adv76xx_fill_format(state, &format->format); |
Laurent Pinchart | 539b33b | 2014-01-26 18:42:37 -0300 | [diff] [blame] | 1849 | |
| 1850 | if (format->which == V4L2_SUBDEV_FORMAT_TRY) { |
| 1851 | struct v4l2_mbus_framefmt *fmt; |
| 1852 | |
Hans Verkuil | f723413 | 2015-03-04 01:47:54 -0800 | [diff] [blame] | 1853 | fmt = v4l2_subdev_get_try_format(sd, cfg, format->pad); |
Laurent Pinchart | 539b33b | 2014-01-26 18:42:37 -0300 | [diff] [blame] | 1854 | format->format.code = fmt->code; |
| 1855 | } else { |
| 1856 | format->format.code = state->format->code; |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1857 | } |
Laurent Pinchart | 539b33b | 2014-01-26 18:42:37 -0300 | [diff] [blame] | 1858 | |
| 1859 | return 0; |
| 1860 | } |
| 1861 | |
Hans Verkuil | f723413 | 2015-03-04 01:47:54 -0800 | [diff] [blame] | 1862 | static int adv76xx_set_format(struct v4l2_subdev *sd, |
| 1863 | struct v4l2_subdev_pad_config *cfg, |
Laurent Pinchart | 539b33b | 2014-01-26 18:42:37 -0300 | [diff] [blame] | 1864 | struct v4l2_subdev_format *format) |
| 1865 | { |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1866 | struct adv76xx_state *state = to_state(sd); |
| 1867 | const struct adv76xx_format_info *info; |
Laurent Pinchart | 539b33b | 2014-01-26 18:42:37 -0300 | [diff] [blame] | 1868 | |
| 1869 | if (format->pad != state->source_pad) |
| 1870 | return -EINVAL; |
| 1871 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1872 | info = adv76xx_format_info(state, format->format.code); |
Laurent Pinchart | 539b33b | 2014-01-26 18:42:37 -0300 | [diff] [blame] | 1873 | if (info == NULL) |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1874 | info = adv76xx_format_info(state, MEDIA_BUS_FMT_YUYV8_2X8); |
Laurent Pinchart | 539b33b | 2014-01-26 18:42:37 -0300 | [diff] [blame] | 1875 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1876 | adv76xx_fill_format(state, &format->format); |
Laurent Pinchart | 539b33b | 2014-01-26 18:42:37 -0300 | [diff] [blame] | 1877 | format->format.code = info->code; |
| 1878 | |
| 1879 | if (format->which == V4L2_SUBDEV_FORMAT_TRY) { |
| 1880 | struct v4l2_mbus_framefmt *fmt; |
| 1881 | |
Hans Verkuil | f723413 | 2015-03-04 01:47:54 -0800 | [diff] [blame] | 1882 | fmt = v4l2_subdev_get_try_format(sd, cfg, format->pad); |
Laurent Pinchart | 539b33b | 2014-01-26 18:42:37 -0300 | [diff] [blame] | 1883 | fmt->code = format->format.code; |
| 1884 | } else { |
| 1885 | state->format = info; |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1886 | adv76xx_setup_format(state); |
Laurent Pinchart | 539b33b | 2014-01-26 18:42:37 -0300 | [diff] [blame] | 1887 | } |
| 1888 | |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1889 | return 0; |
| 1890 | } |
| 1891 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1892 | static int adv76xx_isr(struct v4l2_subdev *sd, u32 status, bool *handled) |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1893 | { |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1894 | struct adv76xx_state *state = to_state(sd); |
| 1895 | const struct adv76xx_chip_info *info = state->info; |
Mats Randgaard | f24d229 | 2013-12-10 10:15:13 -0300 | [diff] [blame] | 1896 | const u8 irq_reg_0x43 = io_read(sd, 0x43); |
| 1897 | const u8 irq_reg_0x6b = io_read(sd, 0x6b); |
| 1898 | const u8 irq_reg_0x70 = io_read(sd, 0x70); |
| 1899 | u8 fmt_change_digital; |
| 1900 | u8 fmt_change; |
| 1901 | u8 tx_5v; |
| 1902 | |
| 1903 | if (irq_reg_0x43) |
| 1904 | io_write(sd, 0x44, irq_reg_0x43); |
| 1905 | if (irq_reg_0x70) |
| 1906 | io_write(sd, 0x71, irq_reg_0x70); |
| 1907 | if (irq_reg_0x6b) |
| 1908 | io_write(sd, 0x6c, irq_reg_0x6b); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1909 | |
Mats Randgaard | ff4f80f | 2013-12-05 10:24:05 -0300 | [diff] [blame] | 1910 | v4l2_dbg(2, debug, sd, "%s: ", __func__); |
| 1911 | |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1912 | /* format change */ |
Mats Randgaard | f24d229 | 2013-12-10 10:15:13 -0300 | [diff] [blame] | 1913 | fmt_change = irq_reg_0x43 & 0x98; |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 1914 | fmt_change_digital = is_digital_input(sd) |
| 1915 | ? irq_reg_0x6b & info->fmt_change_digital_mask |
| 1916 | : 0; |
Mats Randgaard | 14d0323 | 2013-12-05 10:26:11 -0300 | [diff] [blame] | 1917 | |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1918 | if (fmt_change || fmt_change_digital) { |
| 1919 | v4l2_dbg(1, debug, sd, |
Mats Randgaard | 25a64ac | 2013-08-14 07:58:45 -0300 | [diff] [blame] | 1920 | "%s: fmt_change = 0x%x, fmt_change_digital = 0x%x\n", |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1921 | __func__, fmt_change, fmt_change_digital); |
Mats Randgaard | 25a64ac | 2013-08-14 07:58:45 -0300 | [diff] [blame] | 1922 | |
Hans Verkuil | 4851983 | 2015-05-07 10:37:57 -0300 | [diff] [blame^] | 1923 | v4l2_subdev_notify(sd, V4L2_DEVICE_NOTIFY_EVENT, |
| 1924 | (void *)&adv76xx_ev_fmt); |
Mats Randgaard | 25a64ac | 2013-08-14 07:58:45 -0300 | [diff] [blame] | 1925 | |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1926 | if (handled) |
| 1927 | *handled = true; |
| 1928 | } |
Mats Randgaard | f24d229 | 2013-12-10 10:15:13 -0300 | [diff] [blame] | 1929 | /* HDMI/DVI mode */ |
| 1930 | if (irq_reg_0x6b & 0x01) { |
| 1931 | v4l2_dbg(1, debug, sd, "%s: irq %s mode\n", __func__, |
| 1932 | (io_read(sd, 0x6a) & 0x01) ? "HDMI" : "DVI"); |
| 1933 | set_rgb_quantization_range(sd); |
| 1934 | if (handled) |
| 1935 | *handled = true; |
| 1936 | } |
| 1937 | |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1938 | /* tx 5v detect */ |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 1939 | tx_5v = io_read(sd, 0x70) & info->cable_det_mask; |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1940 | if (tx_5v) { |
| 1941 | v4l2_dbg(1, debug, sd, "%s: tx_5v: 0x%x\n", __func__, tx_5v); |
| 1942 | io_write(sd, 0x71, tx_5v); |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1943 | adv76xx_s_detect_tx_5v_ctrl(sd); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1944 | if (handled) |
| 1945 | *handled = true; |
| 1946 | } |
| 1947 | return 0; |
| 1948 | } |
| 1949 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1950 | static int adv76xx_get_edid(struct v4l2_subdev *sd, struct v4l2_edid *edid) |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1951 | { |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1952 | struct adv76xx_state *state = to_state(sd); |
Mats Randgaard | 4a31a93 | 2013-12-10 09:45:00 -0300 | [diff] [blame] | 1953 | u8 *data = NULL; |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1954 | |
Hans Verkuil | dd9ac11 | 2014-11-07 09:34:57 -0300 | [diff] [blame] | 1955 | memset(edid->reserved, 0, sizeof(edid->reserved)); |
Mats Randgaard | 4a31a93 | 2013-12-10 09:45:00 -0300 | [diff] [blame] | 1956 | |
| 1957 | switch (edid->pad) { |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 1958 | case ADV76XX_PAD_HDMI_PORT_A: |
Laurent Pinchart | c784b1e | 2014-01-29 10:08:58 -0300 | [diff] [blame] | 1959 | case ADV7604_PAD_HDMI_PORT_B: |
| 1960 | case ADV7604_PAD_HDMI_PORT_C: |
| 1961 | case ADV7604_PAD_HDMI_PORT_D: |
Mats Randgaard | 4a31a93 | 2013-12-10 09:45:00 -0300 | [diff] [blame] | 1962 | if (state->edid.present & (1 << edid->pad)) |
| 1963 | data = state->edid.edid; |
| 1964 | break; |
| 1965 | default: |
| 1966 | return -EINVAL; |
Mats Randgaard | 4a31a93 | 2013-12-10 09:45:00 -0300 | [diff] [blame] | 1967 | } |
Hans Verkuil | dd9ac11 | 2014-11-07 09:34:57 -0300 | [diff] [blame] | 1968 | |
| 1969 | if (edid->start_block == 0 && edid->blocks == 0) { |
| 1970 | edid->blocks = data ? state->edid.blocks : 0; |
| 1971 | return 0; |
| 1972 | } |
| 1973 | |
| 1974 | if (data == NULL) |
Mats Randgaard | 4a31a93 | 2013-12-10 09:45:00 -0300 | [diff] [blame] | 1975 | return -ENODATA; |
| 1976 | |
Hans Verkuil | dd9ac11 | 2014-11-07 09:34:57 -0300 | [diff] [blame] | 1977 | if (edid->start_block >= state->edid.blocks) |
| 1978 | return -EINVAL; |
| 1979 | |
| 1980 | if (edid->start_block + edid->blocks > state->edid.blocks) |
| 1981 | edid->blocks = state->edid.blocks - edid->start_block; |
| 1982 | |
| 1983 | memcpy(edid->edid, data + edid->start_block * 128, edid->blocks * 128); |
| 1984 | |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 1985 | return 0; |
| 1986 | } |
| 1987 | |
Mats Randgaard | dd08beb | 2013-12-10 09:57:09 -0300 | [diff] [blame] | 1988 | static int get_edid_spa_location(const u8 *edid) |
Mats Randgaard | 3e86aa8 | 2013-12-10 09:55:18 -0300 | [diff] [blame] | 1989 | { |
| 1990 | u8 d; |
| 1991 | |
| 1992 | if ((edid[0x7e] != 1) || |
| 1993 | (edid[0x80] != 0x02) || |
| 1994 | (edid[0x81] != 0x03)) { |
| 1995 | return -1; |
| 1996 | } |
| 1997 | |
| 1998 | /* search Vendor Specific Data Block (tag 3) */ |
| 1999 | d = edid[0x82] & 0x7f; |
| 2000 | if (d > 4) { |
| 2001 | int i = 0x84; |
| 2002 | int end = 0x80 + d; |
| 2003 | |
| 2004 | do { |
| 2005 | u8 tag = edid[i] >> 5; |
| 2006 | u8 len = edid[i] & 0x1f; |
| 2007 | |
| 2008 | if ((tag == 3) && (len >= 5)) |
| 2009 | return i + 4; |
| 2010 | i += len + 1; |
| 2011 | } while (i < end); |
| 2012 | } |
| 2013 | return -1; |
| 2014 | } |
| 2015 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2016 | static int adv76xx_set_edid(struct v4l2_subdev *sd, struct v4l2_edid *edid) |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2017 | { |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2018 | struct adv76xx_state *state = to_state(sd); |
| 2019 | const struct adv76xx_chip_info *info = state->info; |
Mats Randgaard | dd08beb | 2013-12-10 09:57:09 -0300 | [diff] [blame] | 2020 | int spa_loc; |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2021 | int err; |
Mats Randgaard | dd08beb | 2013-12-10 09:57:09 -0300 | [diff] [blame] | 2022 | int i; |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2023 | |
Hans Verkuil | dd9ac11 | 2014-11-07 09:34:57 -0300 | [diff] [blame] | 2024 | memset(edid->reserved, 0, sizeof(edid->reserved)); |
| 2025 | |
Laurent Pinchart | c784b1e | 2014-01-29 10:08:58 -0300 | [diff] [blame] | 2026 | if (edid->pad > ADV7604_PAD_HDMI_PORT_D) |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2027 | return -EINVAL; |
| 2028 | if (edid->start_block != 0) |
| 2029 | return -EINVAL; |
| 2030 | if (edid->blocks == 0) { |
Mats Randgaard | 3e86aa8 | 2013-12-10 09:55:18 -0300 | [diff] [blame] | 2031 | /* Disable hotplug and I2C access to EDID RAM from DDC port */ |
Mats Randgaard | 4a31a93 | 2013-12-10 09:45:00 -0300 | [diff] [blame] | 2032 | state->edid.present &= ~(1 << edid->pad); |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2033 | adv76xx_set_hpd(state, state->edid.present); |
Laurent Pinchart | 22d97e5 | 2014-01-30 17:17:42 -0300 | [diff] [blame] | 2034 | rep_write_clr_set(sd, info->edid_enable_reg, 0x0f, state->edid.present); |
Mats Randgaard | 3e86aa8 | 2013-12-10 09:55:18 -0300 | [diff] [blame] | 2035 | |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2036 | /* Fall back to a 16:9 aspect ratio */ |
| 2037 | state->aspect_ratio.numerator = 16; |
| 2038 | state->aspect_ratio.denominator = 9; |
Mats Randgaard | 3e86aa8 | 2013-12-10 09:55:18 -0300 | [diff] [blame] | 2039 | |
| 2040 | if (!state->edid.present) |
| 2041 | state->edid.blocks = 0; |
| 2042 | |
| 2043 | v4l2_dbg(2, debug, sd, "%s: clear EDID pad %d, edid.present = 0x%x\n", |
| 2044 | __func__, edid->pad, state->edid.present); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2045 | return 0; |
| 2046 | } |
Mats Randgaard | 4a31a93 | 2013-12-10 09:45:00 -0300 | [diff] [blame] | 2047 | if (edid->blocks > 2) { |
| 2048 | edid->blocks = 2; |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2049 | return -E2BIG; |
Mats Randgaard | 4a31a93 | 2013-12-10 09:45:00 -0300 | [diff] [blame] | 2050 | } |
Mats Randgaard | 4a31a93 | 2013-12-10 09:45:00 -0300 | [diff] [blame] | 2051 | |
Mats Randgaard | dd08beb | 2013-12-10 09:57:09 -0300 | [diff] [blame] | 2052 | v4l2_dbg(2, debug, sd, "%s: write EDID pad %d, edid.present = 0x%x\n", |
| 2053 | __func__, edid->pad, state->edid.present); |
| 2054 | |
Mats Randgaard | 3e86aa8 | 2013-12-10 09:55:18 -0300 | [diff] [blame] | 2055 | /* Disable hotplug and I2C access to EDID RAM from DDC port */ |
Mats Randgaard | 4a31a93 | 2013-12-10 09:45:00 -0300 | [diff] [blame] | 2056 | cancel_delayed_work_sync(&state->delayed_work_enable_hotplug); |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2057 | adv76xx_set_hpd(state, 0); |
Laurent Pinchart | 22d97e5 | 2014-01-30 17:17:42 -0300 | [diff] [blame] | 2058 | rep_write_clr_set(sd, info->edid_enable_reg, 0x0f, 0x00); |
Mats Randgaard | 3e86aa8 | 2013-12-10 09:55:18 -0300 | [diff] [blame] | 2059 | |
Mats Randgaard | dd08beb | 2013-12-10 09:57:09 -0300 | [diff] [blame] | 2060 | spa_loc = get_edid_spa_location(edid->edid); |
| 2061 | if (spa_loc < 0) |
| 2062 | spa_loc = 0xc0; /* Default value [REF_02, p. 116] */ |
| 2063 | |
Mats Randgaard | 3e86aa8 | 2013-12-10 09:55:18 -0300 | [diff] [blame] | 2064 | switch (edid->pad) { |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2065 | case ADV76XX_PAD_HDMI_PORT_A: |
Mats Randgaard | dd08beb | 2013-12-10 09:57:09 -0300 | [diff] [blame] | 2066 | state->spa_port_a[0] = edid->edid[spa_loc]; |
| 2067 | state->spa_port_a[1] = edid->edid[spa_loc + 1]; |
Mats Randgaard | 3e86aa8 | 2013-12-10 09:55:18 -0300 | [diff] [blame] | 2068 | break; |
Laurent Pinchart | c784b1e | 2014-01-29 10:08:58 -0300 | [diff] [blame] | 2069 | case ADV7604_PAD_HDMI_PORT_B: |
Mats Randgaard | dd08beb | 2013-12-10 09:57:09 -0300 | [diff] [blame] | 2070 | rep_write(sd, 0x70, edid->edid[spa_loc]); |
| 2071 | rep_write(sd, 0x71, edid->edid[spa_loc + 1]); |
Mats Randgaard | 3e86aa8 | 2013-12-10 09:55:18 -0300 | [diff] [blame] | 2072 | break; |
Laurent Pinchart | c784b1e | 2014-01-29 10:08:58 -0300 | [diff] [blame] | 2073 | case ADV7604_PAD_HDMI_PORT_C: |
Mats Randgaard | dd08beb | 2013-12-10 09:57:09 -0300 | [diff] [blame] | 2074 | rep_write(sd, 0x72, edid->edid[spa_loc]); |
| 2075 | rep_write(sd, 0x73, edid->edid[spa_loc + 1]); |
Mats Randgaard | 3e86aa8 | 2013-12-10 09:55:18 -0300 | [diff] [blame] | 2076 | break; |
Laurent Pinchart | c784b1e | 2014-01-29 10:08:58 -0300 | [diff] [blame] | 2077 | case ADV7604_PAD_HDMI_PORT_D: |
Mats Randgaard | dd08beb | 2013-12-10 09:57:09 -0300 | [diff] [blame] | 2078 | rep_write(sd, 0x74, edid->edid[spa_loc]); |
| 2079 | rep_write(sd, 0x75, edid->edid[spa_loc + 1]); |
Mats Randgaard | 3e86aa8 | 2013-12-10 09:55:18 -0300 | [diff] [blame] | 2080 | break; |
Mats Randgaard | dd08beb | 2013-12-10 09:57:09 -0300 | [diff] [blame] | 2081 | default: |
| 2082 | return -EINVAL; |
Mats Randgaard | 3e86aa8 | 2013-12-10 09:55:18 -0300 | [diff] [blame] | 2083 | } |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 2084 | |
| 2085 | if (info->type == ADV7604) { |
| 2086 | rep_write(sd, 0x76, spa_loc & 0xff); |
Laurent Pinchart | 22d97e5 | 2014-01-30 17:17:42 -0300 | [diff] [blame] | 2087 | rep_write_clr_set(sd, 0x77, 0x40, (spa_loc & 0x100) >> 2); |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 2088 | } else { |
| 2089 | /* FIXME: Where is the SPA location LSB register ? */ |
Laurent Pinchart | 22d97e5 | 2014-01-30 17:17:42 -0300 | [diff] [blame] | 2090 | rep_write_clr_set(sd, 0x71, 0x01, (spa_loc & 0x100) >> 8); |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 2091 | } |
Mats Randgaard | 3e86aa8 | 2013-12-10 09:55:18 -0300 | [diff] [blame] | 2092 | |
Mats Randgaard | dd08beb | 2013-12-10 09:57:09 -0300 | [diff] [blame] | 2093 | edid->edid[spa_loc] = state->spa_port_a[0]; |
| 2094 | edid->edid[spa_loc + 1] = state->spa_port_a[1]; |
Mats Randgaard | 4a31a93 | 2013-12-10 09:45:00 -0300 | [diff] [blame] | 2095 | |
| 2096 | memcpy(state->edid.edid, edid->edid, 128 * edid->blocks); |
| 2097 | state->edid.blocks = edid->blocks; |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2098 | state->aspect_ratio = v4l2_calc_aspect_ratio(edid->edid[0x15], |
| 2099 | edid->edid[0x16]); |
Mats Randgaard | 3e86aa8 | 2013-12-10 09:55:18 -0300 | [diff] [blame] | 2100 | state->edid.present |= 1 << edid->pad; |
Mats Randgaard | 4a31a93 | 2013-12-10 09:45:00 -0300 | [diff] [blame] | 2101 | |
| 2102 | err = edid_write_block(sd, 128 * edid->blocks, state->edid.edid); |
| 2103 | if (err < 0) { |
Mats Randgaard | 3e86aa8 | 2013-12-10 09:55:18 -0300 | [diff] [blame] | 2104 | v4l2_err(sd, "error %d writing edid pad %d\n", err, edid->pad); |
Mats Randgaard | 4a31a93 | 2013-12-10 09:45:00 -0300 | [diff] [blame] | 2105 | return err; |
| 2106 | } |
| 2107 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2108 | /* adv76xx calculates the checksums and enables I2C access to internal |
Mats Randgaard | dd08beb | 2013-12-10 09:57:09 -0300 | [diff] [blame] | 2109 | EDID RAM from DDC port. */ |
Laurent Pinchart | 22d97e5 | 2014-01-30 17:17:42 -0300 | [diff] [blame] | 2110 | rep_write_clr_set(sd, info->edid_enable_reg, 0x0f, state->edid.present); |
Mats Randgaard | dd08beb | 2013-12-10 09:57:09 -0300 | [diff] [blame] | 2111 | |
| 2112 | for (i = 0; i < 1000; i++) { |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 2113 | if (rep_read(sd, info->edid_status_reg) & state->edid.present) |
Mats Randgaard | dd08beb | 2013-12-10 09:57:09 -0300 | [diff] [blame] | 2114 | break; |
| 2115 | mdelay(1); |
| 2116 | } |
| 2117 | if (i == 1000) { |
| 2118 | v4l2_err(sd, "error enabling edid (0x%x)\n", state->edid.present); |
| 2119 | return -EIO; |
| 2120 | } |
| 2121 | |
Mats Randgaard | 4a31a93 | 2013-12-10 09:45:00 -0300 | [diff] [blame] | 2122 | /* enable hotplug after 100 ms */ |
| 2123 | queue_delayed_work(state->work_queues, |
| 2124 | &state->delayed_work_enable_hotplug, HZ / 10); |
| 2125 | return 0; |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2126 | } |
| 2127 | |
| 2128 | /*********** avi info frame CEA-861-E **************/ |
| 2129 | |
| 2130 | static void print_avi_infoframe(struct v4l2_subdev *sd) |
| 2131 | { |
| 2132 | int i; |
| 2133 | u8 buf[14]; |
| 2134 | u8 avi_len; |
| 2135 | u8 avi_ver; |
| 2136 | |
Martin Bugge | bb88f32 | 2013-08-14 08:52:46 -0300 | [diff] [blame] | 2137 | if (!is_hdmi(sd)) { |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2138 | v4l2_info(sd, "receive DVI-D signal (AVI infoframe not supported)\n"); |
| 2139 | return; |
| 2140 | } |
| 2141 | if (!(io_read(sd, 0x60) & 0x01)) { |
| 2142 | v4l2_info(sd, "AVI infoframe not received\n"); |
| 2143 | return; |
| 2144 | } |
| 2145 | |
| 2146 | if (io_read(sd, 0x83) & 0x01) { |
| 2147 | v4l2_info(sd, "AVI infoframe checksum error has occurred earlier\n"); |
| 2148 | io_write(sd, 0x85, 0x01); /* clear AVI_INF_CKS_ERR_RAW */ |
| 2149 | if (io_read(sd, 0x83) & 0x01) { |
| 2150 | v4l2_info(sd, "AVI infoframe checksum error still present\n"); |
| 2151 | io_write(sd, 0x85, 0x01); /* clear AVI_INF_CKS_ERR_RAW */ |
| 2152 | } |
| 2153 | } |
| 2154 | |
| 2155 | avi_len = infoframe_read(sd, 0xe2); |
| 2156 | avi_ver = infoframe_read(sd, 0xe1); |
| 2157 | v4l2_info(sd, "AVI infoframe version %d (%d byte)\n", |
| 2158 | avi_ver, avi_len); |
| 2159 | |
| 2160 | if (avi_ver != 0x02) |
| 2161 | return; |
| 2162 | |
| 2163 | for (i = 0; i < 14; i++) |
| 2164 | buf[i] = infoframe_read(sd, i); |
| 2165 | |
| 2166 | v4l2_info(sd, |
| 2167 | "\t%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n", |
| 2168 | buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7], |
| 2169 | buf[8], buf[9], buf[10], buf[11], buf[12], buf[13]); |
| 2170 | } |
| 2171 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2172 | static int adv76xx_log_status(struct v4l2_subdev *sd) |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2173 | { |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2174 | struct adv76xx_state *state = to_state(sd); |
| 2175 | const struct adv76xx_chip_info *info = state->info; |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2176 | struct v4l2_dv_timings timings; |
| 2177 | struct stdi_readback stdi; |
| 2178 | u8 reg_io_0x02 = io_read(sd, 0x02); |
Laurent Pinchart | 4a2ccdd | 2014-01-08 20:26:55 -0300 | [diff] [blame] | 2179 | u8 edid_enabled; |
| 2180 | u8 cable_det; |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2181 | |
Lars-Peter Clausen | f216ccb | 2013-11-25 16:15:29 -0300 | [diff] [blame] | 2182 | static const char * const csc_coeff_sel_rb[16] = { |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2183 | "bypassed", "YPbPr601 -> RGB", "reserved", "YPbPr709 -> RGB", |
| 2184 | "reserved", "RGB -> YPbPr601", "reserved", "RGB -> YPbPr709", |
| 2185 | "reserved", "YPbPr709 -> YPbPr601", "YPbPr601 -> YPbPr709", |
| 2186 | "reserved", "reserved", "reserved", "reserved", "manual" |
| 2187 | }; |
Lars-Peter Clausen | f216ccb | 2013-11-25 16:15:29 -0300 | [diff] [blame] | 2188 | static const char * const input_color_space_txt[16] = { |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2189 | "RGB limited range (16-235)", "RGB full range (0-255)", |
| 2190 | "YCbCr Bt.601 (16-235)", "YCbCr Bt.709 (16-235)", |
Mats Randgaard | 9833239 | 2013-12-05 10:05:58 -0300 | [diff] [blame] | 2191 | "xvYCC Bt.601", "xvYCC Bt.709", |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2192 | "YCbCr Bt.601 (0-255)", "YCbCr Bt.709 (0-255)", |
| 2193 | "invalid", "invalid", "invalid", "invalid", "invalid", |
| 2194 | "invalid", "invalid", "automatic" |
| 2195 | }; |
Lars-Peter Clausen | f216ccb | 2013-11-25 16:15:29 -0300 | [diff] [blame] | 2196 | static const char * const rgb_quantization_range_txt[] = { |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2197 | "Automatic", |
| 2198 | "RGB limited range (16-235)", |
| 2199 | "RGB full range (0-255)", |
| 2200 | }; |
Lars-Peter Clausen | f216ccb | 2013-11-25 16:15:29 -0300 | [diff] [blame] | 2201 | static const char * const deep_color_mode_txt[4] = { |
Martin Bugge | bb88f32 | 2013-08-14 08:52:46 -0300 | [diff] [blame] | 2202 | "8-bits per channel", |
| 2203 | "10-bits per channel", |
| 2204 | "12-bits per channel", |
| 2205 | "16-bits per channel (not supported)" |
| 2206 | }; |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2207 | |
| 2208 | v4l2_info(sd, "-----Chip status-----\n"); |
| 2209 | v4l2_info(sd, "Chip power: %s\n", no_power(sd) ? "off" : "on"); |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 2210 | edid_enabled = rep_read(sd, info->edid_status_reg); |
Mats Randgaard | 4a31a93 | 2013-12-10 09:45:00 -0300 | [diff] [blame] | 2211 | v4l2_info(sd, "EDID enabled port A: %s, B: %s, C: %s, D: %s\n", |
Laurent Pinchart | 4a2ccdd | 2014-01-08 20:26:55 -0300 | [diff] [blame] | 2212 | ((edid_enabled & 0x01) ? "Yes" : "No"), |
| 2213 | ((edid_enabled & 0x02) ? "Yes" : "No"), |
| 2214 | ((edid_enabled & 0x04) ? "Yes" : "No"), |
| 2215 | ((edid_enabled & 0x08) ? "Yes" : "No")); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2216 | v4l2_info(sd, "CEC: %s\n", !!(cec_read(sd, 0x2a) & 0x01) ? |
| 2217 | "enabled" : "disabled"); |
| 2218 | |
| 2219 | v4l2_info(sd, "-----Signal status-----\n"); |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 2220 | cable_det = info->read_cable_det(sd); |
Mats Randgaard | 4a31a93 | 2013-12-10 09:45:00 -0300 | [diff] [blame] | 2221 | v4l2_info(sd, "Cable detected (+5V power) port A: %s, B: %s, C: %s, D: %s\n", |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 2222 | ((cable_det & 0x01) ? "Yes" : "No"), |
| 2223 | ((cable_det & 0x02) ? "Yes" : "No"), |
Laurent Pinchart | 4a2ccdd | 2014-01-08 20:26:55 -0300 | [diff] [blame] | 2224 | ((cable_det & 0x04) ? "Yes" : "No"), |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 2225 | ((cable_det & 0x08) ? "Yes" : "No")); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2226 | v4l2_info(sd, "TMDS signal detected: %s\n", |
| 2227 | no_signal_tmds(sd) ? "false" : "true"); |
| 2228 | v4l2_info(sd, "TMDS signal locked: %s\n", |
| 2229 | no_lock_tmds(sd) ? "false" : "true"); |
| 2230 | v4l2_info(sd, "SSPD locked: %s\n", no_lock_sspd(sd) ? "false" : "true"); |
| 2231 | v4l2_info(sd, "STDI locked: %s\n", no_lock_stdi(sd) ? "false" : "true"); |
| 2232 | v4l2_info(sd, "CP locked: %s\n", no_lock_cp(sd) ? "false" : "true"); |
| 2233 | v4l2_info(sd, "CP free run: %s\n", |
jean-michel.hautbois@vodalys.com | 5851462 | 2015-02-06 11:37:58 -0300 | [diff] [blame] | 2234 | (in_free_run(sd)) ? "on" : "off"); |
Hans Verkuil | ccbd5bc | 2012-10-16 10:02:05 -0300 | [diff] [blame] | 2235 | v4l2_info(sd, "Prim-mode = 0x%x, video std = 0x%x, v_freq = 0x%x\n", |
| 2236 | io_read(sd, 0x01) & 0x0f, io_read(sd, 0x00) & 0x3f, |
| 2237 | (io_read(sd, 0x01) & 0x70) >> 4); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2238 | |
| 2239 | v4l2_info(sd, "-----Video Timings-----\n"); |
| 2240 | if (read_stdi(sd, &stdi)) |
| 2241 | v4l2_info(sd, "STDI: not locked\n"); |
| 2242 | else |
| 2243 | v4l2_info(sd, "STDI: lcf (frame height - 1) = %d, bl = %d, lcvs (vsync) = %d, %s, %chsync, %cvsync\n", |
| 2244 | stdi.lcf, stdi.bl, stdi.lcvs, |
| 2245 | stdi.interlaced ? "interlaced" : "progressive", |
| 2246 | stdi.hs_pol, stdi.vs_pol); |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2247 | if (adv76xx_query_dv_timings(sd, &timings)) |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2248 | v4l2_info(sd, "No video detected\n"); |
| 2249 | else |
Hans Verkuil | 11d034c | 2013-08-15 08:05:59 -0300 | [diff] [blame] | 2250 | v4l2_print_dv_timings(sd->name, "Detected format: ", |
| 2251 | &timings, true); |
| 2252 | v4l2_print_dv_timings(sd->name, "Configured format: ", |
| 2253 | &state->timings, true); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2254 | |
Mats Randgaard | 76eb2d3 | 2013-08-14 08:56:57 -0300 | [diff] [blame] | 2255 | if (no_signal(sd)) |
| 2256 | return 0; |
| 2257 | |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2258 | v4l2_info(sd, "-----Color space-----\n"); |
| 2259 | v4l2_info(sd, "RGB quantization range ctrl: %s\n", |
| 2260 | rgb_quantization_range_txt[state->rgb_quantization_range]); |
| 2261 | v4l2_info(sd, "Input color space: %s\n", |
| 2262 | input_color_space_txt[reg_io_0x02 >> 4]); |
| 2263 | v4l2_info(sd, "Output color space: %s %s, saturator %s\n", |
| 2264 | (reg_io_0x02 & 0x02) ? "RGB" : "YCbCr", |
| 2265 | (reg_io_0x02 & 0x04) ? "(16-235)" : "(0-255)", |
| 2266 | ((reg_io_0x02 & 0x04) ^ (reg_io_0x02 & 0x01)) ? |
Mats Randgaard | 76eb2d3 | 2013-08-14 08:56:57 -0300 | [diff] [blame] | 2267 | "enabled" : "disabled"); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2268 | v4l2_info(sd, "Color space conversion: %s\n", |
jean-michel.hautbois@vodalys.com | 80f4944 | 2015-02-04 11:16:00 -0300 | [diff] [blame] | 2269 | csc_coeff_sel_rb[cp_read(sd, info->cp_csc) >> 4]); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2270 | |
Mats Randgaard | 4a31a93 | 2013-12-10 09:45:00 -0300 | [diff] [blame] | 2271 | if (!is_digital_input(sd)) |
Mats Randgaard | 76eb2d3 | 2013-08-14 08:56:57 -0300 | [diff] [blame] | 2272 | return 0; |
| 2273 | |
| 2274 | v4l2_info(sd, "-----%s status-----\n", is_hdmi(sd) ? "HDMI" : "DVI-D"); |
Mats Randgaard | 4a31a93 | 2013-12-10 09:45:00 -0300 | [diff] [blame] | 2275 | v4l2_info(sd, "Digital video port selected: %c\n", |
| 2276 | (hdmi_read(sd, 0x00) & 0x03) + 'A'); |
| 2277 | v4l2_info(sd, "HDCP encrypted content: %s\n", |
| 2278 | (hdmi_read(sd, 0x05) & 0x40) ? "true" : "false"); |
Mats Randgaard | 76eb2d3 | 2013-08-14 08:56:57 -0300 | [diff] [blame] | 2279 | v4l2_info(sd, "HDCP keys read: %s%s\n", |
| 2280 | (hdmi_read(sd, 0x04) & 0x20) ? "yes" : "no", |
| 2281 | (hdmi_read(sd, 0x04) & 0x10) ? "ERROR" : ""); |
Hans Verkuil | 77639ff | 2014-09-12 06:02:02 -0300 | [diff] [blame] | 2282 | if (is_hdmi(sd)) { |
Mats Randgaard | 76eb2d3 | 2013-08-14 08:56:57 -0300 | [diff] [blame] | 2283 | bool audio_pll_locked = hdmi_read(sd, 0x04) & 0x01; |
| 2284 | bool audio_sample_packet_detect = hdmi_read(sd, 0x18) & 0x01; |
| 2285 | bool audio_mute = io_read(sd, 0x65) & 0x40; |
| 2286 | |
| 2287 | v4l2_info(sd, "Audio: pll %s, samples %s, %s\n", |
| 2288 | audio_pll_locked ? "locked" : "not locked", |
| 2289 | audio_sample_packet_detect ? "detected" : "not detected", |
| 2290 | audio_mute ? "muted" : "enabled"); |
| 2291 | if (audio_pll_locked && audio_sample_packet_detect) { |
| 2292 | v4l2_info(sd, "Audio format: %s\n", |
| 2293 | (hdmi_read(sd, 0x07) & 0x20) ? "multi-channel" : "stereo"); |
| 2294 | } |
| 2295 | v4l2_info(sd, "Audio CTS: %u\n", (hdmi_read(sd, 0x5b) << 12) + |
| 2296 | (hdmi_read(sd, 0x5c) << 8) + |
| 2297 | (hdmi_read(sd, 0x5d) & 0xf0)); |
| 2298 | v4l2_info(sd, "Audio N: %u\n", ((hdmi_read(sd, 0x5d) & 0x0f) << 16) + |
| 2299 | (hdmi_read(sd, 0x5e) << 8) + |
| 2300 | hdmi_read(sd, 0x5f)); |
| 2301 | v4l2_info(sd, "AV Mute: %s\n", (hdmi_read(sd, 0x04) & 0x40) ? "on" : "off"); |
| 2302 | |
| 2303 | v4l2_info(sd, "Deep color mode: %s\n", deep_color_mode_txt[(hdmi_read(sd, 0x0b) & 0x60) >> 5]); |
| 2304 | |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2305 | print_avi_infoframe(sd); |
| 2306 | } |
| 2307 | |
| 2308 | return 0; |
| 2309 | } |
| 2310 | |
| 2311 | /* ----------------------------------------------------------------------- */ |
| 2312 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2313 | static const struct v4l2_ctrl_ops adv76xx_ctrl_ops = { |
| 2314 | .s_ctrl = adv76xx_s_ctrl, |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2315 | }; |
| 2316 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2317 | static const struct v4l2_subdev_core_ops adv76xx_core_ops = { |
| 2318 | .log_status = adv76xx_log_status, |
| 2319 | .interrupt_service_routine = adv76xx_isr, |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2320 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2321 | .g_register = adv76xx_g_register, |
| 2322 | .s_register = adv76xx_s_register, |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2323 | #endif |
| 2324 | }; |
| 2325 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2326 | static const struct v4l2_subdev_video_ops adv76xx_video_ops = { |
| 2327 | .s_routing = adv76xx_s_routing, |
| 2328 | .g_input_status = adv76xx_g_input_status, |
| 2329 | .s_dv_timings = adv76xx_s_dv_timings, |
| 2330 | .g_dv_timings = adv76xx_g_dv_timings, |
| 2331 | .query_dv_timings = adv76xx_query_dv_timings, |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2332 | }; |
| 2333 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2334 | static const struct v4l2_subdev_pad_ops adv76xx_pad_ops = { |
| 2335 | .enum_mbus_code = adv76xx_enum_mbus_code, |
| 2336 | .get_fmt = adv76xx_get_format, |
| 2337 | .set_fmt = adv76xx_set_format, |
| 2338 | .get_edid = adv76xx_get_edid, |
| 2339 | .set_edid = adv76xx_set_edid, |
| 2340 | .dv_timings_cap = adv76xx_dv_timings_cap, |
| 2341 | .enum_dv_timings = adv76xx_enum_dv_timings, |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2342 | }; |
| 2343 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2344 | static const struct v4l2_subdev_ops adv76xx_ops = { |
| 2345 | .core = &adv76xx_core_ops, |
| 2346 | .video = &adv76xx_video_ops, |
| 2347 | .pad = &adv76xx_pad_ops, |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2348 | }; |
| 2349 | |
| 2350 | /* -------------------------- custom ctrls ---------------------------------- */ |
| 2351 | |
| 2352 | static const struct v4l2_ctrl_config adv7604_ctrl_analog_sampling_phase = { |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2353 | .ops = &adv76xx_ctrl_ops, |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2354 | .id = V4L2_CID_ADV_RX_ANALOG_SAMPLING_PHASE, |
| 2355 | .name = "Analog Sampling Phase", |
| 2356 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 2357 | .min = 0, |
| 2358 | .max = 0x1f, |
| 2359 | .step = 1, |
| 2360 | .def = 0, |
| 2361 | }; |
| 2362 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2363 | static const struct v4l2_ctrl_config adv76xx_ctrl_free_run_color_manual = { |
| 2364 | .ops = &adv76xx_ctrl_ops, |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2365 | .id = V4L2_CID_ADV_RX_FREE_RUN_COLOR_MANUAL, |
| 2366 | .name = "Free Running Color, Manual", |
| 2367 | .type = V4L2_CTRL_TYPE_BOOLEAN, |
| 2368 | .min = false, |
| 2369 | .max = true, |
| 2370 | .step = 1, |
| 2371 | .def = false, |
| 2372 | }; |
| 2373 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2374 | static const struct v4l2_ctrl_config adv76xx_ctrl_free_run_color = { |
| 2375 | .ops = &adv76xx_ctrl_ops, |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2376 | .id = V4L2_CID_ADV_RX_FREE_RUN_COLOR, |
| 2377 | .name = "Free Running Color", |
| 2378 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 2379 | .min = 0x0, |
| 2380 | .max = 0xffffff, |
| 2381 | .step = 0x1, |
| 2382 | .def = 0x0, |
| 2383 | }; |
| 2384 | |
| 2385 | /* ----------------------------------------------------------------------- */ |
| 2386 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2387 | static int adv76xx_core_init(struct v4l2_subdev *sd) |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2388 | { |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2389 | struct adv76xx_state *state = to_state(sd); |
| 2390 | const struct adv76xx_chip_info *info = state->info; |
| 2391 | struct adv76xx_platform_data *pdata = &state->pdata; |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2392 | |
| 2393 | hdmi_write(sd, 0x48, |
| 2394 | (pdata->disable_pwrdnb ? 0x80 : 0) | |
| 2395 | (pdata->disable_cable_det_rst ? 0x40 : 0)); |
| 2396 | |
| 2397 | disable_input(sd); |
| 2398 | |
Laurent Pinchart | 5ef54b5 | 2014-01-31 10:57:27 -0300 | [diff] [blame] | 2399 | if (pdata->default_input >= 0 && |
| 2400 | pdata->default_input < state->source_pad) { |
| 2401 | state->selected_input = pdata->default_input; |
| 2402 | select_input(sd); |
| 2403 | enable_input(sd); |
| 2404 | } |
| 2405 | |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2406 | /* power */ |
| 2407 | io_write(sd, 0x0c, 0x42); /* Power up part and power down VDP */ |
| 2408 | io_write(sd, 0x0b, 0x44); /* Power down ESDP block */ |
| 2409 | cp_write(sd, 0xcf, 0x01); /* Power down macrovision */ |
| 2410 | |
| 2411 | /* video format */ |
Laurent Pinchart | 22d97e5 | 2014-01-30 17:17:42 -0300 | [diff] [blame] | 2412 | io_write_clr_set(sd, 0x02, 0x0f, |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2413 | pdata->alt_gamma << 3 | |
| 2414 | pdata->op_656_range << 2 | |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2415 | pdata->alt_data_sat << 0); |
Laurent Pinchart | 22d97e5 | 2014-01-30 17:17:42 -0300 | [diff] [blame] | 2416 | io_write_clr_set(sd, 0x05, 0x0e, pdata->blank_data << 3 | |
Laurent Pinchart | 539b33b | 2014-01-26 18:42:37 -0300 | [diff] [blame] | 2417 | pdata->insert_av_codes << 2 | |
| 2418 | pdata->replicate_av_codes << 1); |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2419 | adv76xx_setup_format(state); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2420 | |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2421 | cp_write(sd, 0x69, 0x30); /* Enable CP CSC */ |
Martin Bugge | 9890869 | 2013-12-20 05:14:57 -0300 | [diff] [blame] | 2422 | |
| 2423 | /* VS, HS polarities */ |
Laurent Pinchart | 1b5ab87 | 2014-02-04 19:57:56 -0300 | [diff] [blame] | 2424 | io_write(sd, 0x06, 0xa0 | pdata->inv_vs_pol << 2 | |
| 2425 | pdata->inv_hs_pol << 1 | pdata->inv_llc_pol); |
Mikhail Khelik | f31b62e | 2013-12-20 05:12:00 -0300 | [diff] [blame] | 2426 | |
| 2427 | /* Adjust drive strength */ |
| 2428 | io_write(sd, 0x14, 0x40 | pdata->dr_str_data << 4 | |
| 2429 | pdata->dr_str_clk << 2 | |
| 2430 | pdata->dr_str_sync); |
| 2431 | |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2432 | cp_write(sd, 0xba, (pdata->hdmi_free_run_mode << 1) | 0x01); /* HDMI free run */ |
| 2433 | cp_write(sd, 0xf3, 0xdc); /* Low threshold to enter/exit free run mode */ |
| 2434 | cp_write(sd, 0xf9, 0x23); /* STDI ch. 1 - LCVS change threshold - |
Hans Verkuil | 8093964 | 2012-10-16 05:46:21 -0300 | [diff] [blame] | 2435 | ADI recommended setting [REF_01, c. 2.3.3] */ |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2436 | cp_write(sd, 0x45, 0x23); /* STDI ch. 2 - LCVS change threshold - |
Hans Verkuil | 8093964 | 2012-10-16 05:46:21 -0300 | [diff] [blame] | 2437 | ADI recommended setting [REF_01, c. 2.3.3] */ |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2438 | cp_write(sd, 0xc9, 0x2d); /* use prim_mode and vid_std as free run resolution |
| 2439 | for digital formats */ |
| 2440 | |
Mats Randgaard | 5474b98 | 2013-12-05 10:33:41 -0300 | [diff] [blame] | 2441 | /* HDMI audio */ |
Laurent Pinchart | 22d97e5 | 2014-01-30 17:17:42 -0300 | [diff] [blame] | 2442 | hdmi_write_clr_set(sd, 0x15, 0x03, 0x03); /* Mute on FIFO over-/underflow [REF_01, c. 1.2.18] */ |
| 2443 | hdmi_write_clr_set(sd, 0x1a, 0x0e, 0x08); /* Wait 1 s before unmute */ |
| 2444 | hdmi_write_clr_set(sd, 0x68, 0x06, 0x06); /* FIFO reset on over-/underflow [REF_01, c. 1.2.19] */ |
Mats Randgaard | 5474b98 | 2013-12-05 10:33:41 -0300 | [diff] [blame] | 2445 | |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2446 | /* TODO from platform data */ |
| 2447 | afe_write(sd, 0xb5, 0x01); /* Setting MCLK to 256Fs */ |
| 2448 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2449 | if (adv76xx_has_afe(state)) { |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 2450 | afe_write(sd, 0x02, pdata->ain_sel); /* Select analog input muxing mode */ |
Laurent Pinchart | 22d97e5 | 2014-01-30 17:17:42 -0300 | [diff] [blame] | 2451 | io_write_clr_set(sd, 0x30, 1 << 4, pdata->output_bus_lsb_to_msb << 4); |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 2452 | } |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2453 | |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2454 | /* interrupts */ |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 2455 | io_write(sd, 0x40, 0xc0 | pdata->int1_config); /* Configure INT1 */ |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2456 | io_write(sd, 0x46, 0x98); /* Enable SSPD, STDI and CP unlocked interrupts */ |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 2457 | io_write(sd, 0x6e, info->fmt_change_digital_mask); /* Enable V_LOCKED and DE_REGEN_LCK interrupts */ |
| 2458 | io_write(sd, 0x73, info->cable_det_mask); /* Enable cable detection (+5v) interrupts */ |
| 2459 | info->setup_irqs(sd); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2460 | |
| 2461 | return v4l2_ctrl_handler_setup(sd->ctrl_handler); |
| 2462 | } |
| 2463 | |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 2464 | static void adv7604_setup_irqs(struct v4l2_subdev *sd) |
| 2465 | { |
| 2466 | io_write(sd, 0x41, 0xd7); /* STDI irq for any change, disable INT2 */ |
| 2467 | } |
| 2468 | |
| 2469 | static void adv7611_setup_irqs(struct v4l2_subdev *sd) |
| 2470 | { |
| 2471 | io_write(sd, 0x41, 0xd0); /* STDI irq for any change, disable INT2 */ |
| 2472 | } |
| 2473 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2474 | static void adv76xx_unregister_clients(struct adv76xx_state *state) |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2475 | { |
Laurent Pinchart | 05cacb1 | 2014-01-30 16:32:21 -0300 | [diff] [blame] | 2476 | unsigned int i; |
| 2477 | |
| 2478 | for (i = 1; i < ARRAY_SIZE(state->i2c_clients); ++i) { |
| 2479 | if (state->i2c_clients[i]) |
| 2480 | i2c_unregister_device(state->i2c_clients[i]); |
| 2481 | } |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2482 | } |
| 2483 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2484 | static struct i2c_client *adv76xx_dummy_client(struct v4l2_subdev *sd, |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2485 | u8 addr, u8 io_reg) |
| 2486 | { |
| 2487 | struct i2c_client *client = v4l2_get_subdevdata(sd); |
| 2488 | |
| 2489 | if (addr) |
| 2490 | io_write(sd, io_reg, addr << 1); |
| 2491 | return i2c_new_dummy(client->adapter, io_read(sd, io_reg) >> 1); |
| 2492 | } |
| 2493 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2494 | static const struct adv76xx_reg_seq adv7604_recommended_settings_afe[] = { |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 2495 | /* reset ADI recommended settings for HDMI: */ |
| 2496 | /* "ADV7604 Register Settings Recommendations (rev. 2.5, June 2010)" p. 4. */ |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2497 | { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x0d), 0x04 }, /* HDMI filter optimization */ |
| 2498 | { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x0d), 0x04 }, /* HDMI filter optimization */ |
| 2499 | { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x3d), 0x00 }, /* DDC bus active pull-up control */ |
| 2500 | { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x3e), 0x74 }, /* TMDS PLL optimization */ |
| 2501 | { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x4e), 0x3b }, /* TMDS PLL optimization */ |
| 2502 | { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x57), 0x74 }, /* TMDS PLL optimization */ |
| 2503 | { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x58), 0x63 }, /* TMDS PLL optimization */ |
| 2504 | { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x8d), 0x18 }, /* equaliser */ |
| 2505 | { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x8e), 0x34 }, /* equaliser */ |
| 2506 | { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x93), 0x88 }, /* equaliser */ |
| 2507 | { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x94), 0x2e }, /* equaliser */ |
| 2508 | { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x96), 0x00 }, /* enable automatic EQ changing */ |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 2509 | |
| 2510 | /* set ADI recommended settings for digitizer */ |
| 2511 | /* "ADV7604 Register Settings Recommendations (rev. 2.5, June 2010)" p. 17. */ |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2512 | { ADV76XX_REG(ADV76XX_PAGE_AFE, 0x12), 0x7b }, /* ADC noise shaping filter controls */ |
| 2513 | { ADV76XX_REG(ADV76XX_PAGE_AFE, 0x0c), 0x1f }, /* CP core gain controls */ |
| 2514 | { ADV76XX_REG(ADV76XX_PAGE_CP, 0x3e), 0x04 }, /* CP core pre-gain control */ |
| 2515 | { ADV76XX_REG(ADV76XX_PAGE_CP, 0xc3), 0x39 }, /* CP coast control. Graphics mode */ |
| 2516 | { ADV76XX_REG(ADV76XX_PAGE_CP, 0x40), 0x5c }, /* CP core pre-gain control. Graphics mode */ |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 2517 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2518 | { ADV76XX_REG_SEQ_TERM, 0 }, |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 2519 | }; |
| 2520 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2521 | static const struct adv76xx_reg_seq adv7604_recommended_settings_hdmi[] = { |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 2522 | /* set ADI recommended settings for HDMI: */ |
| 2523 | /* "ADV7604 Register Settings Recommendations (rev. 2.5, June 2010)" p. 4. */ |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2524 | { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x0d), 0x84 }, /* HDMI filter optimization */ |
| 2525 | { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x3d), 0x10 }, /* DDC bus active pull-up control */ |
| 2526 | { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x3e), 0x39 }, /* TMDS PLL optimization */ |
| 2527 | { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x4e), 0x3b }, /* TMDS PLL optimization */ |
| 2528 | { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x57), 0xb6 }, /* TMDS PLL optimization */ |
| 2529 | { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x58), 0x03 }, /* TMDS PLL optimization */ |
| 2530 | { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x8d), 0x18 }, /* equaliser */ |
| 2531 | { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x8e), 0x34 }, /* equaliser */ |
| 2532 | { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x93), 0x8b }, /* equaliser */ |
| 2533 | { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x94), 0x2d }, /* equaliser */ |
| 2534 | { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x96), 0x01 }, /* enable automatic EQ changing */ |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 2535 | |
| 2536 | /* reset ADI recommended settings for digitizer */ |
| 2537 | /* "ADV7604 Register Settings Recommendations (rev. 2.5, June 2010)" p. 17. */ |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2538 | { ADV76XX_REG(ADV76XX_PAGE_AFE, 0x12), 0xfb }, /* ADC noise shaping filter controls */ |
| 2539 | { ADV76XX_REG(ADV76XX_PAGE_AFE, 0x0c), 0x0d }, /* CP core gain controls */ |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 2540 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2541 | { ADV76XX_REG_SEQ_TERM, 0 }, |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 2542 | }; |
| 2543 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2544 | static const struct adv76xx_reg_seq adv7611_recommended_settings_hdmi[] = { |
Lars-Peter Clausen | c41ad9c | 2014-06-17 08:52:24 -0300 | [diff] [blame] | 2545 | /* ADV7611 Register Settings Recommendations Rev 1.5, May 2014 */ |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2546 | { ADV76XX_REG(ADV76XX_PAGE_CP, 0x6c), 0x00 }, |
| 2547 | { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x9b), 0x03 }, |
| 2548 | { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x6f), 0x08 }, |
| 2549 | { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x85), 0x1f }, |
| 2550 | { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x87), 0x70 }, |
| 2551 | { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x57), 0xda }, |
| 2552 | { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x58), 0x01 }, |
| 2553 | { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x03), 0x98 }, |
| 2554 | { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x4c), 0x44 }, |
| 2555 | { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x8d), 0x04 }, |
| 2556 | { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x8e), 0x1e }, |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 2557 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2558 | { ADV76XX_REG_SEQ_TERM, 0 }, |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 2559 | }; |
| 2560 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2561 | static const struct adv76xx_chip_info adv76xx_chip_info[] = { |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 2562 | [ADV7604] = { |
| 2563 | .type = ADV7604, |
| 2564 | .has_afe = true, |
Laurent Pinchart | c784b1e | 2014-01-29 10:08:58 -0300 | [diff] [blame] | 2565 | .max_port = ADV7604_PAD_VGA_COMP, |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 2566 | .num_dv_ports = 4, |
| 2567 | .edid_enable_reg = 0x77, |
| 2568 | .edid_status_reg = 0x7d, |
| 2569 | .lcf_reg = 0xb3, |
| 2570 | .tdms_lock_mask = 0xe0, |
| 2571 | .cable_det_mask = 0x1e, |
| 2572 | .fmt_change_digital_mask = 0xc1, |
jean-michel.hautbois@vodalys.com | 80f4944 | 2015-02-04 11:16:00 -0300 | [diff] [blame] | 2573 | .cp_csc = 0xfc, |
Laurent Pinchart | 539b33b | 2014-01-26 18:42:37 -0300 | [diff] [blame] | 2574 | .formats = adv7604_formats, |
| 2575 | .nformats = ARRAY_SIZE(adv7604_formats), |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 2576 | .set_termination = adv7604_set_termination, |
| 2577 | .setup_irqs = adv7604_setup_irqs, |
| 2578 | .read_hdmi_pixelclock = adv7604_read_hdmi_pixelclock, |
| 2579 | .read_cable_det = adv7604_read_cable_det, |
| 2580 | .recommended_settings = { |
| 2581 | [0] = adv7604_recommended_settings_afe, |
| 2582 | [1] = adv7604_recommended_settings_hdmi, |
| 2583 | }, |
| 2584 | .num_recommended_settings = { |
| 2585 | [0] = ARRAY_SIZE(adv7604_recommended_settings_afe), |
| 2586 | [1] = ARRAY_SIZE(adv7604_recommended_settings_hdmi), |
| 2587 | }, |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2588 | .page_mask = BIT(ADV76XX_PAGE_IO) | BIT(ADV7604_PAGE_AVLINK) | |
| 2589 | BIT(ADV76XX_PAGE_CEC) | BIT(ADV76XX_PAGE_INFOFRAME) | |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 2590 | BIT(ADV7604_PAGE_ESDP) | BIT(ADV7604_PAGE_DPP) | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2591 | BIT(ADV76XX_PAGE_AFE) | BIT(ADV76XX_PAGE_REP) | |
| 2592 | BIT(ADV76XX_PAGE_EDID) | BIT(ADV76XX_PAGE_HDMI) | |
| 2593 | BIT(ADV76XX_PAGE_TEST) | BIT(ADV76XX_PAGE_CP) | |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 2594 | BIT(ADV7604_PAGE_VDP), |
jean-michel.hautbois@vodalys.com | 5380baa | 2015-04-09 05:25:46 -0300 | [diff] [blame] | 2595 | .linewidth_mask = 0xfff, |
| 2596 | .field0_height_mask = 0xfff, |
| 2597 | .field1_height_mask = 0xfff, |
| 2598 | .hfrontporch_mask = 0x3ff, |
| 2599 | .hsync_mask = 0x3ff, |
| 2600 | .hbackporch_mask = 0x3ff, |
| 2601 | .field0_vfrontporch_mask = 0x1fff, |
| 2602 | .field0_vsync_mask = 0x1fff, |
| 2603 | .field0_vbackporch_mask = 0x1fff, |
| 2604 | .field1_vfrontporch_mask = 0x1fff, |
| 2605 | .field1_vsync_mask = 0x1fff, |
| 2606 | .field1_vbackporch_mask = 0x1fff, |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 2607 | }, |
| 2608 | [ADV7611] = { |
| 2609 | .type = ADV7611, |
| 2610 | .has_afe = false, |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2611 | .max_port = ADV76XX_PAD_HDMI_PORT_A, |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 2612 | .num_dv_ports = 1, |
| 2613 | .edid_enable_reg = 0x74, |
| 2614 | .edid_status_reg = 0x76, |
| 2615 | .lcf_reg = 0xa3, |
| 2616 | .tdms_lock_mask = 0x43, |
| 2617 | .cable_det_mask = 0x01, |
| 2618 | .fmt_change_digital_mask = 0x03, |
jean-michel.hautbois@vodalys.com | 80f4944 | 2015-02-04 11:16:00 -0300 | [diff] [blame] | 2619 | .cp_csc = 0xf4, |
Laurent Pinchart | 539b33b | 2014-01-26 18:42:37 -0300 | [diff] [blame] | 2620 | .formats = adv7611_formats, |
| 2621 | .nformats = ARRAY_SIZE(adv7611_formats), |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 2622 | .set_termination = adv7611_set_termination, |
| 2623 | .setup_irqs = adv7611_setup_irqs, |
| 2624 | .read_hdmi_pixelclock = adv7611_read_hdmi_pixelclock, |
| 2625 | .read_cable_det = adv7611_read_cable_det, |
| 2626 | .recommended_settings = { |
| 2627 | [1] = adv7611_recommended_settings_hdmi, |
| 2628 | }, |
| 2629 | .num_recommended_settings = { |
| 2630 | [1] = ARRAY_SIZE(adv7611_recommended_settings_hdmi), |
| 2631 | }, |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2632 | .page_mask = BIT(ADV76XX_PAGE_IO) | BIT(ADV76XX_PAGE_CEC) | |
| 2633 | BIT(ADV76XX_PAGE_INFOFRAME) | BIT(ADV76XX_PAGE_AFE) | |
| 2634 | BIT(ADV76XX_PAGE_REP) | BIT(ADV76XX_PAGE_EDID) | |
| 2635 | BIT(ADV76XX_PAGE_HDMI) | BIT(ADV76XX_PAGE_CP), |
jean-michel.hautbois@vodalys.com | 5380baa | 2015-04-09 05:25:46 -0300 | [diff] [blame] | 2636 | .linewidth_mask = 0x1fff, |
| 2637 | .field0_height_mask = 0x1fff, |
| 2638 | .field1_height_mask = 0x1fff, |
| 2639 | .hfrontporch_mask = 0x1fff, |
| 2640 | .hsync_mask = 0x1fff, |
| 2641 | .hbackporch_mask = 0x1fff, |
| 2642 | .field0_vfrontporch_mask = 0x3fff, |
| 2643 | .field0_vsync_mask = 0x3fff, |
| 2644 | .field0_vbackporch_mask = 0x3fff, |
| 2645 | .field1_vfrontporch_mask = 0x3fff, |
| 2646 | .field1_vsync_mask = 0x3fff, |
| 2647 | .field1_vbackporch_mask = 0x3fff, |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 2648 | }, |
| 2649 | }; |
| 2650 | |
Fabian Frederick | 7f099a7 | 2015-03-16 16:54:33 -0300 | [diff] [blame] | 2651 | static const struct i2c_device_id adv76xx_i2c_id[] = { |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2652 | { "adv7604", (kernel_ulong_t)&adv76xx_chip_info[ADV7604] }, |
| 2653 | { "adv7611", (kernel_ulong_t)&adv76xx_chip_info[ADV7611] }, |
Laurent Pinchart | f82f313 | 2013-11-25 16:19:08 -0300 | [diff] [blame] | 2654 | { } |
| 2655 | }; |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2656 | MODULE_DEVICE_TABLE(i2c, adv76xx_i2c_id); |
Laurent Pinchart | f82f313 | 2013-11-25 16:19:08 -0300 | [diff] [blame] | 2657 | |
Fabian Frederick | 7f099a7 | 2015-03-16 16:54:33 -0300 | [diff] [blame] | 2658 | static const struct of_device_id adv76xx_of_id[] __maybe_unused = { |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2659 | { .compatible = "adi,adv7611", .data = &adv76xx_chip_info[ADV7611] }, |
Laurent Pinchart | f82f313 | 2013-11-25 16:19:08 -0300 | [diff] [blame] | 2660 | { } |
| 2661 | }; |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2662 | MODULE_DEVICE_TABLE(of, adv76xx_of_id); |
Laurent Pinchart | f82f313 | 2013-11-25 16:19:08 -0300 | [diff] [blame] | 2663 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2664 | static int adv76xx_parse_dt(struct adv76xx_state *state) |
Laurent Pinchart | f82f313 | 2013-11-25 16:19:08 -0300 | [diff] [blame] | 2665 | { |
Laurent Pinchart | 6fa8804 | 2014-02-04 20:23:16 -0300 | [diff] [blame] | 2666 | struct v4l2_of_endpoint bus_cfg; |
| 2667 | struct device_node *endpoint; |
| 2668 | struct device_node *np; |
| 2669 | unsigned int flags; |
| 2670 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2671 | np = state->i2c_clients[ADV76XX_PAGE_IO]->dev.of_node; |
Laurent Pinchart | 6fa8804 | 2014-02-04 20:23:16 -0300 | [diff] [blame] | 2672 | |
| 2673 | /* Parse the endpoint. */ |
| 2674 | endpoint = of_graph_get_next_endpoint(np, NULL); |
| 2675 | if (!endpoint) |
| 2676 | return -EINVAL; |
| 2677 | |
| 2678 | v4l2_of_parse_endpoint(endpoint, &bus_cfg); |
| 2679 | of_node_put(endpoint); |
| 2680 | |
| 2681 | flags = bus_cfg.bus.parallel.flags; |
| 2682 | |
| 2683 | if (flags & V4L2_MBUS_HSYNC_ACTIVE_HIGH) |
| 2684 | state->pdata.inv_hs_pol = 1; |
| 2685 | |
| 2686 | if (flags & V4L2_MBUS_VSYNC_ACTIVE_HIGH) |
| 2687 | state->pdata.inv_vs_pol = 1; |
| 2688 | |
| 2689 | if (flags & V4L2_MBUS_PCLK_SAMPLE_RISING) |
| 2690 | state->pdata.inv_llc_pol = 1; |
| 2691 | |
| 2692 | if (bus_cfg.bus_type == V4L2_MBUS_BT656) { |
| 2693 | state->pdata.insert_av_codes = 1; |
| 2694 | state->pdata.op_656_range = 1; |
| 2695 | } |
| 2696 | |
Laurent Pinchart | f82f313 | 2013-11-25 16:19:08 -0300 | [diff] [blame] | 2697 | /* Disable the interrupt for now as no DT-based board uses it. */ |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2698 | state->pdata.int1_config = ADV76XX_INT1_CONFIG_DISABLED; |
Laurent Pinchart | f82f313 | 2013-11-25 16:19:08 -0300 | [diff] [blame] | 2699 | |
| 2700 | /* Use the default I2C addresses. */ |
| 2701 | state->pdata.i2c_addresses[ADV7604_PAGE_AVLINK] = 0x42; |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2702 | state->pdata.i2c_addresses[ADV76XX_PAGE_CEC] = 0x40; |
| 2703 | state->pdata.i2c_addresses[ADV76XX_PAGE_INFOFRAME] = 0x3e; |
Laurent Pinchart | f82f313 | 2013-11-25 16:19:08 -0300 | [diff] [blame] | 2704 | state->pdata.i2c_addresses[ADV7604_PAGE_ESDP] = 0x38; |
| 2705 | state->pdata.i2c_addresses[ADV7604_PAGE_DPP] = 0x3c; |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2706 | state->pdata.i2c_addresses[ADV76XX_PAGE_AFE] = 0x26; |
| 2707 | state->pdata.i2c_addresses[ADV76XX_PAGE_REP] = 0x32; |
| 2708 | state->pdata.i2c_addresses[ADV76XX_PAGE_EDID] = 0x36; |
| 2709 | state->pdata.i2c_addresses[ADV76XX_PAGE_HDMI] = 0x34; |
| 2710 | state->pdata.i2c_addresses[ADV76XX_PAGE_TEST] = 0x30; |
| 2711 | state->pdata.i2c_addresses[ADV76XX_PAGE_CP] = 0x22; |
Laurent Pinchart | f82f313 | 2013-11-25 16:19:08 -0300 | [diff] [blame] | 2712 | state->pdata.i2c_addresses[ADV7604_PAGE_VDP] = 0x24; |
| 2713 | |
| 2714 | /* Hardcode the remaining platform data fields. */ |
| 2715 | state->pdata.disable_pwrdnb = 0; |
| 2716 | state->pdata.disable_cable_det_rst = 0; |
| 2717 | state->pdata.default_input = -1; |
| 2718 | state->pdata.blank_data = 1; |
Laurent Pinchart | f82f313 | 2013-11-25 16:19:08 -0300 | [diff] [blame] | 2719 | state->pdata.alt_data_sat = 1; |
Laurent Pinchart | f82f313 | 2013-11-25 16:19:08 -0300 | [diff] [blame] | 2720 | state->pdata.op_format_mode_sel = ADV7604_OP_FORMAT_MODE0; |
| 2721 | state->pdata.bus_order = ADV7604_BUS_ORDER_RGB; |
| 2722 | |
| 2723 | return 0; |
| 2724 | } |
| 2725 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2726 | static int adv76xx_probe(struct i2c_client *client, |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2727 | const struct i2c_device_id *id) |
| 2728 | { |
Hans Verkuil | 591b72f | 2013-12-17 10:05:13 -0300 | [diff] [blame] | 2729 | static const struct v4l2_dv_timings cea640x480 = |
| 2730 | V4L2_DV_BT_CEA_640X480P59_94; |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2731 | struct adv76xx_state *state; |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2732 | struct v4l2_ctrl_handler *hdl; |
| 2733 | struct v4l2_subdev *sd; |
Laurent Pinchart | c784b1e | 2014-01-29 10:08:58 -0300 | [diff] [blame] | 2734 | unsigned int i; |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 2735 | u16 val; |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2736 | int err; |
| 2737 | |
| 2738 | /* Check if the adapter supports the needed features */ |
| 2739 | if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
| 2740 | return -EIO; |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2741 | v4l_dbg(1, debug, client, "detecting adv76xx client on address 0x%x\n", |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2742 | client->addr << 1); |
| 2743 | |
Laurent Pinchart | c02b211 | 2013-05-02 08:29:43 -0300 | [diff] [blame] | 2744 | state = devm_kzalloc(&client->dev, sizeof(*state), GFP_KERNEL); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2745 | if (!state) { |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2746 | v4l_err(client, "Could not allocate adv76xx_state memory!\n"); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2747 | return -ENOMEM; |
| 2748 | } |
| 2749 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2750 | state->i2c_clients[ADV76XX_PAGE_IO] = client; |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 2751 | |
Mats Randgaard | 25a64ac | 2013-08-14 07:58:45 -0300 | [diff] [blame] | 2752 | /* initialize variables */ |
| 2753 | state->restart_stdi_once = true; |
Mats Randgaard | ff4f80f | 2013-12-05 10:24:05 -0300 | [diff] [blame] | 2754 | state->selected_input = ~0; |
Mats Randgaard | 25a64ac | 2013-08-14 07:58:45 -0300 | [diff] [blame] | 2755 | |
Laurent Pinchart | f82f313 | 2013-11-25 16:19:08 -0300 | [diff] [blame] | 2756 | if (IS_ENABLED(CONFIG_OF) && client->dev.of_node) { |
| 2757 | const struct of_device_id *oid; |
| 2758 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2759 | oid = of_match_node(adv76xx_of_id, client->dev.of_node); |
Laurent Pinchart | f82f313 | 2013-11-25 16:19:08 -0300 | [diff] [blame] | 2760 | state->info = oid->data; |
| 2761 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2762 | err = adv76xx_parse_dt(state); |
Laurent Pinchart | f82f313 | 2013-11-25 16:19:08 -0300 | [diff] [blame] | 2763 | if (err < 0) { |
| 2764 | v4l_err(client, "DT parsing error\n"); |
| 2765 | return err; |
| 2766 | } |
| 2767 | } else if (client->dev.platform_data) { |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2768 | struct adv76xx_platform_data *pdata = client->dev.platform_data; |
Laurent Pinchart | f82f313 | 2013-11-25 16:19:08 -0300 | [diff] [blame] | 2769 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2770 | state->info = (const struct adv76xx_chip_info *)id->driver_data; |
Laurent Pinchart | f82f313 | 2013-11-25 16:19:08 -0300 | [diff] [blame] | 2771 | state->pdata = *pdata; |
| 2772 | } else { |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2773 | v4l_err(client, "No platform data!\n"); |
Laurent Pinchart | c02b211 | 2013-05-02 08:29:43 -0300 | [diff] [blame] | 2774 | return -ENODEV; |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2775 | } |
Laurent Pinchart | e9d50e9 | 2014-01-30 18:37:08 -0300 | [diff] [blame] | 2776 | |
| 2777 | /* Request GPIOs. */ |
| 2778 | for (i = 0; i < state->info->num_dv_ports; ++i) { |
| 2779 | state->hpd_gpio[i] = |
Uwe Kleine-König | 269bd13 | 2015-03-02 04:00:44 -0300 | [diff] [blame] | 2780 | devm_gpiod_get_index_optional(&client->dev, "hpd", i, |
| 2781 | GPIOD_OUT_LOW); |
Laurent Pinchart | e9d50e9 | 2014-01-30 18:37:08 -0300 | [diff] [blame] | 2782 | if (IS_ERR(state->hpd_gpio[i])) |
Uwe Kleine-König | 269bd13 | 2015-03-02 04:00:44 -0300 | [diff] [blame] | 2783 | return PTR_ERR(state->hpd_gpio[i]); |
Laurent Pinchart | e9d50e9 | 2014-01-30 18:37:08 -0300 | [diff] [blame] | 2784 | |
Uwe Kleine-König | 269bd13 | 2015-03-02 04:00:44 -0300 | [diff] [blame] | 2785 | if (state->hpd_gpio[i]) |
| 2786 | v4l_info(client, "Handling HPD %u GPIO\n", i); |
Laurent Pinchart | e9d50e9 | 2014-01-30 18:37:08 -0300 | [diff] [blame] | 2787 | } |
| 2788 | |
Hans Verkuil | 591b72f | 2013-12-17 10:05:13 -0300 | [diff] [blame] | 2789 | state->timings = cea640x480; |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2790 | state->format = adv76xx_format_info(state, MEDIA_BUS_FMT_YUYV8_2X8); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2791 | |
| 2792 | sd = &state->sd; |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2793 | v4l2_i2c_subdev_init(sd, client, &adv76xx_ops); |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 2794 | snprintf(sd->name, sizeof(sd->name), "%s %d-%04x", |
| 2795 | id->name, i2c_adapter_id(client->adapter), |
| 2796 | client->addr); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2797 | sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2798 | |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 2799 | /* |
| 2800 | * Verify that the chip is present. On ADV7604 the RD_INFO register only |
| 2801 | * identifies the revision, while on ADV7611 it identifies the model as |
| 2802 | * well. Use the HDMI slave address on ADV7604 and RD_INFO on ADV7611. |
| 2803 | */ |
| 2804 | if (state->info->type == ADV7604) { |
| 2805 | val = adv_smbus_read_byte_data_check(client, 0xfb, false); |
| 2806 | if (val != 0x68) { |
| 2807 | v4l2_info(sd, "not an adv7604 on address 0x%x\n", |
| 2808 | client->addr << 1); |
| 2809 | return -ENODEV; |
| 2810 | } |
| 2811 | } else { |
| 2812 | val = (adv_smbus_read_byte_data_check(client, 0xea, false) << 8) |
| 2813 | | (adv_smbus_read_byte_data_check(client, 0xeb, false) << 0); |
| 2814 | if (val != 0x2051) { |
| 2815 | v4l2_info(sd, "not an adv7611 on address 0x%x\n", |
| 2816 | client->addr << 1); |
| 2817 | return -ENODEV; |
| 2818 | } |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2819 | } |
| 2820 | |
| 2821 | /* control handlers */ |
| 2822 | hdl = &state->hdl; |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2823 | v4l2_ctrl_handler_init(hdl, adv76xx_has_afe(state) ? 9 : 8); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2824 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2825 | v4l2_ctrl_new_std(hdl, &adv76xx_ctrl_ops, |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2826 | V4L2_CID_BRIGHTNESS, -128, 127, 1, 0); |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2827 | v4l2_ctrl_new_std(hdl, &adv76xx_ctrl_ops, |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2828 | V4L2_CID_CONTRAST, 0, 255, 1, 128); |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2829 | v4l2_ctrl_new_std(hdl, &adv76xx_ctrl_ops, |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2830 | V4L2_CID_SATURATION, 0, 255, 1, 128); |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2831 | v4l2_ctrl_new_std(hdl, &adv76xx_ctrl_ops, |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2832 | V4L2_CID_HUE, 0, 128, 1, 0); |
| 2833 | |
| 2834 | /* private controls */ |
| 2835 | state->detect_tx_5v_ctrl = v4l2_ctrl_new_std(hdl, NULL, |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 2836 | V4L2_CID_DV_RX_POWER_PRESENT, 0, |
| 2837 | (1 << state->info->num_dv_ports) - 1, 0, 0); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2838 | state->rgb_quantization_range_ctrl = |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2839 | v4l2_ctrl_new_std_menu(hdl, &adv76xx_ctrl_ops, |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2840 | V4L2_CID_DV_RX_RGB_RANGE, V4L2_DV_RGB_RANGE_FULL, |
| 2841 | 0, V4L2_DV_RGB_RANGE_AUTO); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2842 | |
| 2843 | /* custom controls */ |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2844 | if (adv76xx_has_afe(state)) |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 2845 | state->analog_sampling_phase_ctrl = |
| 2846 | v4l2_ctrl_new_custom(hdl, &adv7604_ctrl_analog_sampling_phase, NULL); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2847 | state->free_run_color_manual_ctrl = |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2848 | v4l2_ctrl_new_custom(hdl, &adv76xx_ctrl_free_run_color_manual, NULL); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2849 | state->free_run_color_ctrl = |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2850 | v4l2_ctrl_new_custom(hdl, &adv76xx_ctrl_free_run_color, NULL); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2851 | |
| 2852 | sd->ctrl_handler = hdl; |
| 2853 | if (hdl->error) { |
| 2854 | err = hdl->error; |
| 2855 | goto err_hdl; |
| 2856 | } |
Hans Verkuil | 8c0eadb | 2013-08-22 06:11:17 -0300 | [diff] [blame] | 2857 | state->detect_tx_5v_ctrl->is_private = true; |
| 2858 | state->rgb_quantization_range_ctrl->is_private = true; |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2859 | if (adv76xx_has_afe(state)) |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 2860 | state->analog_sampling_phase_ctrl->is_private = true; |
Hans Verkuil | 8c0eadb | 2013-08-22 06:11:17 -0300 | [diff] [blame] | 2861 | state->free_run_color_manual_ctrl->is_private = true; |
| 2862 | state->free_run_color_ctrl->is_private = true; |
| 2863 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2864 | if (adv76xx_s_detect_tx_5v_ctrl(sd)) { |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2865 | err = -ENODEV; |
| 2866 | goto err_hdl; |
| 2867 | } |
| 2868 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2869 | for (i = 1; i < ADV76XX_PAGE_MAX; ++i) { |
Laurent Pinchart | 05cacb1 | 2014-01-30 16:32:21 -0300 | [diff] [blame] | 2870 | if (!(BIT(i) & state->info->page_mask)) |
| 2871 | continue; |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2872 | |
Laurent Pinchart | 05cacb1 | 2014-01-30 16:32:21 -0300 | [diff] [blame] | 2873 | state->i2c_clients[i] = |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2874 | adv76xx_dummy_client(sd, state->pdata.i2c_addresses[i], |
Laurent Pinchart | 05cacb1 | 2014-01-30 16:32:21 -0300 | [diff] [blame] | 2875 | 0xf2 + i); |
| 2876 | if (state->i2c_clients[i] == NULL) { |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 2877 | err = -ENOMEM; |
Laurent Pinchart | 05cacb1 | 2014-01-30 16:32:21 -0300 | [diff] [blame] | 2878 | v4l2_err(sd, "failed to create i2c client %u\n", i); |
Lars-Peter Clausen | d42010a | 2013-11-25 15:45:07 -0300 | [diff] [blame] | 2879 | goto err_i2c; |
| 2880 | } |
| 2881 | } |
Laurent Pinchart | 05cacb1 | 2014-01-30 16:32:21 -0300 | [diff] [blame] | 2882 | |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2883 | /* work queues */ |
| 2884 | state->work_queues = create_singlethread_workqueue(client->name); |
| 2885 | if (!state->work_queues) { |
| 2886 | v4l2_err(sd, "Could not create work queue\n"); |
| 2887 | err = -ENOMEM; |
| 2888 | goto err_i2c; |
| 2889 | } |
| 2890 | |
| 2891 | INIT_DELAYED_WORK(&state->delayed_work_enable_hotplug, |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2892 | adv76xx_delayed_work_enable_hotplug); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2893 | |
Laurent Pinchart | c784b1e | 2014-01-29 10:08:58 -0300 | [diff] [blame] | 2894 | state->source_pad = state->info->num_dv_ports |
| 2895 | + (state->info->has_afe ? 2 : 0); |
| 2896 | for (i = 0; i < state->source_pad; ++i) |
| 2897 | state->pads[i].flags = MEDIA_PAD_FL_SINK; |
| 2898 | state->pads[state->source_pad].flags = MEDIA_PAD_FL_SOURCE; |
| 2899 | |
| 2900 | err = media_entity_init(&sd->entity, state->source_pad + 1, |
| 2901 | state->pads, 0); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2902 | if (err) |
| 2903 | goto err_work_queues; |
| 2904 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2905 | err = adv76xx_core_init(sd); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2906 | if (err) |
| 2907 | goto err_entity; |
| 2908 | v4l2_info(sd, "%s found @ 0x%x (%s)\n", client->name, |
| 2909 | client->addr << 1, client->adapter->name); |
Lars-Peter Clausen | bedc393 | 2013-11-25 16:18:02 -0300 | [diff] [blame] | 2910 | |
| 2911 | err = v4l2_async_register_subdev(sd); |
| 2912 | if (err) |
| 2913 | goto err_entity; |
| 2914 | |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2915 | return 0; |
| 2916 | |
| 2917 | err_entity: |
| 2918 | media_entity_cleanup(&sd->entity); |
| 2919 | err_work_queues: |
| 2920 | cancel_delayed_work(&state->delayed_work_enable_hotplug); |
| 2921 | destroy_workqueue(state->work_queues); |
| 2922 | err_i2c: |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2923 | adv76xx_unregister_clients(state); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2924 | err_hdl: |
| 2925 | v4l2_ctrl_handler_free(hdl); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2926 | return err; |
| 2927 | } |
| 2928 | |
| 2929 | /* ----------------------------------------------------------------------- */ |
| 2930 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2931 | static int adv76xx_remove(struct i2c_client *client) |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2932 | { |
| 2933 | struct v4l2_subdev *sd = i2c_get_clientdata(client); |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2934 | struct adv76xx_state *state = to_state(sd); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2935 | |
| 2936 | cancel_delayed_work(&state->delayed_work_enable_hotplug); |
| 2937 | destroy_workqueue(state->work_queues); |
Lars-Peter Clausen | bedc393 | 2013-11-25 16:18:02 -0300 | [diff] [blame] | 2938 | v4l2_async_unregister_subdev(sd); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2939 | media_entity_cleanup(&sd->entity); |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2940 | adv76xx_unregister_clients(to_state(sd)); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2941 | v4l2_ctrl_handler_free(sd->ctrl_handler); |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2942 | return 0; |
| 2943 | } |
| 2944 | |
| 2945 | /* ----------------------------------------------------------------------- */ |
| 2946 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2947 | static struct i2c_driver adv76xx_driver = { |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2948 | .driver = { |
| 2949 | .owner = THIS_MODULE, |
| 2950 | .name = "adv7604", |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2951 | .of_match_table = of_match_ptr(adv76xx_of_id), |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2952 | }, |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2953 | .probe = adv76xx_probe, |
| 2954 | .remove = adv76xx_remove, |
| 2955 | .id_table = adv76xx_i2c_id, |
Hans Verkuil | 54450f5 | 2012-07-18 05:45:16 -0300 | [diff] [blame] | 2956 | }; |
| 2957 | |
Pablo Anton | b44b2e0 | 2015-02-03 14:13:18 -0300 | [diff] [blame] | 2958 | module_i2c_driver(adv76xx_driver); |