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