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