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