blob: d8bf435db86db386a1f48b89c0f181bb505fe99e [file] [log] [blame]
Hans Verkuil54450f52012-07-18 05:45:16 -03001/*
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 Pinchartc72a53c2014-01-30 19:18:34 -030030#include <linux/delay.h>
Laurent Pincharte9d50e92014-01-30 18:37:08 -030031#include <linux/gpio/consumer.h>
Hans Verkuil516613c2015-06-07 07:32:33 -030032#include <linux/hdmi.h>
Laurent Pinchartc72a53c2014-01-30 19:18:34 -030033#include <linux/i2c.h>
Hans Verkuil54450f52012-07-18 05:45:16 -030034#include <linux/kernel.h>
35#include <linux/module.h>
36#include <linux/slab.h>
Laurent Pinchartc72a53c2014-01-30 19:18:34 -030037#include <linux/v4l2-dv-timings.h>
Hans Verkuil54450f52012-07-18 05:45:16 -030038#include <linux/videodev2.h>
39#include <linux/workqueue.h>
Pablo Antonf862f572015-06-19 10:23:06 -030040#include <linux/regmap.h>
Laurent Pinchartc72a53c2014-01-30 19:18:34 -030041
Mauro Carvalho Chehabb5dcee22015-11-10 12:01:44 -020042#include <media/i2c/adv7604.h>
Hans Verkuil41a52372015-09-07 08:12:57 -030043#include <media/cec.h>
Laurent Pinchartc72a53c2014-01-30 19:18:34 -030044#include <media/v4l2-ctrls.h>
45#include <media/v4l2-device.h>
Lars-Peter Clausen09756262015-06-24 13:50:27 -030046#include <media/v4l2-event.h>
Laurent Pinchartc72a53c2014-01-30 19:18:34 -030047#include <media/v4l2-dv-timings.h>
Laurent Pinchart6fa88042014-02-04 20:23:16 -030048#include <media/v4l2-of.h>
Hans Verkuil54450f52012-07-18 05:45:16 -030049
50static int debug;
51module_param(debug, int, 0644);
52MODULE_PARM_DESC(debug, "debug level (0-2)");
53
54MODULE_DESCRIPTION("Analog Devices ADV7604 video decoder driver");
55MODULE_AUTHOR("Hans Verkuil <hans.verkuil@cisco.com>");
56MODULE_AUTHOR("Mats Randgaard <mats.randgaard@cisco.com>");
57MODULE_LICENSE("GPL");
58
59/* ADV7604 system clock frequency */
Pablo Antonb44b2e02015-02-03 14:13:18 -030060#define ADV76XX_FSC (28636360)
Hans Verkuil54450f52012-07-18 05:45:16 -030061
Pablo Antonb44b2e02015-02-03 14:13:18 -030062#define ADV76XX_RGB_OUT (1 << 1)
Laurent Pinchart539b33b2014-01-26 18:42:37 -030063
Pablo Antonb44b2e02015-02-03 14:13:18 -030064#define ADV76XX_OP_FORMAT_SEL_8BIT (0 << 0)
Laurent Pinchart539b33b2014-01-26 18:42:37 -030065#define ADV7604_OP_FORMAT_SEL_10BIT (1 << 0)
Pablo Antonb44b2e02015-02-03 14:13:18 -030066#define ADV76XX_OP_FORMAT_SEL_12BIT (2 << 0)
Laurent Pinchart539b33b2014-01-26 18:42:37 -030067
Pablo Antonb44b2e02015-02-03 14:13:18 -030068#define ADV76XX_OP_MODE_SEL_SDR_422 (0 << 5)
Laurent Pinchart539b33b2014-01-26 18:42:37 -030069#define ADV7604_OP_MODE_SEL_DDR_422 (1 << 5)
Pablo Antonb44b2e02015-02-03 14:13:18 -030070#define ADV76XX_OP_MODE_SEL_SDR_444 (2 << 5)
Laurent Pinchart539b33b2014-01-26 18:42:37 -030071#define ADV7604_OP_MODE_SEL_DDR_444 (3 << 5)
Pablo Antonb44b2e02015-02-03 14:13:18 -030072#define ADV76XX_OP_MODE_SEL_SDR_422_2X (4 << 5)
Laurent Pinchart539b33b2014-01-26 18:42:37 -030073#define ADV7604_OP_MODE_SEL_ADI_CM (5 << 5)
74
Pablo Antonb44b2e02015-02-03 14:13:18 -030075#define ADV76XX_OP_CH_SEL_GBR (0 << 5)
76#define ADV76XX_OP_CH_SEL_GRB (1 << 5)
77#define ADV76XX_OP_CH_SEL_BGR (2 << 5)
78#define ADV76XX_OP_CH_SEL_RGB (3 << 5)
79#define ADV76XX_OP_CH_SEL_BRG (4 << 5)
80#define ADV76XX_OP_CH_SEL_RBG (5 << 5)
Laurent Pinchart539b33b2014-01-26 18:42:37 -030081
Pablo Antonb44b2e02015-02-03 14:13:18 -030082#define ADV76XX_OP_SWAP_CB_CR (1 << 0)
Laurent Pinchart539b33b2014-01-26 18:42:37 -030083
Hans Verkuil41a52372015-09-07 08:12:57 -030084#define ADV76XX_MAX_ADDRS (3)
85
Pablo Antonb44b2e02015-02-03 14:13:18 -030086enum adv76xx_type {
Lars-Peter Clausend42010a2013-11-25 15:45:07 -030087 ADV7604,
88 ADV7611,
William Towle8331d302015-06-03 10:59:51 -030089 ADV7612,
Lars-Peter Clausend42010a2013-11-25 15:45:07 -030090};
91
Pablo Antonb44b2e02015-02-03 14:13:18 -030092struct adv76xx_reg_seq {
Lars-Peter Clausend42010a2013-11-25 15:45:07 -030093 unsigned int reg;
94 u8 val;
95};
96
Pablo Antonb44b2e02015-02-03 14:13:18 -030097struct adv76xx_format_info {
Boris BREZILLONf5fe58f2014-11-10 14:28:29 -030098 u32 code;
Laurent Pinchart539b33b2014-01-26 18:42:37 -030099 u8 op_ch_sel;
100 bool rgb_out;
101 bool swap_cb_cr;
102 u8 op_format_sel;
103};
104
Hans Verkuil516613c2015-06-07 07:32:33 -0300105struct adv76xx_cfg_read_infoframe {
106 const char *desc;
107 u8 present_mask;
108 u8 head_addr;
109 u8 payload_addr;
110};
111
Pablo Antonb44b2e02015-02-03 14:13:18 -0300112struct adv76xx_chip_info {
113 enum adv76xx_type type;
Lars-Peter Clausend42010a2013-11-25 15:45:07 -0300114
115 bool has_afe;
116 unsigned int max_port;
117 unsigned int num_dv_ports;
118
119 unsigned int edid_enable_reg;
120 unsigned int edid_status_reg;
121 unsigned int lcf_reg;
122
123 unsigned int cable_det_mask;
124 unsigned int tdms_lock_mask;
125 unsigned int fmt_change_digital_mask;
jean-michel.hautbois@vodalys.com80f49442015-02-04 11:16:00 -0300126 unsigned int cp_csc;
Lars-Peter Clausend42010a2013-11-25 15:45:07 -0300127
Pablo Antonb44b2e02015-02-03 14:13:18 -0300128 const struct adv76xx_format_info *formats;
Laurent Pinchart539b33b2014-01-26 18:42:37 -0300129 unsigned int nformats;
130
Lars-Peter Clausend42010a2013-11-25 15:45:07 -0300131 void (*set_termination)(struct v4l2_subdev *sd, bool enable);
132 void (*setup_irqs)(struct v4l2_subdev *sd);
133 unsigned int (*read_hdmi_pixelclock)(struct v4l2_subdev *sd);
134 unsigned int (*read_cable_det)(struct v4l2_subdev *sd);
135
136 /* 0 = AFE, 1 = HDMI */
Pablo Antonb44b2e02015-02-03 14:13:18 -0300137 const struct adv76xx_reg_seq *recommended_settings[2];
Lars-Peter Clausend42010a2013-11-25 15:45:07 -0300138 unsigned int num_recommended_settings[2];
139
140 unsigned long page_mask;
jean-michel.hautbois@vodalys.com5380baa2015-04-09 05:25:46 -0300141
142 /* Masks for timings */
143 unsigned int linewidth_mask;
144 unsigned int field0_height_mask;
145 unsigned int field1_height_mask;
146 unsigned int hfrontporch_mask;
147 unsigned int hsync_mask;
148 unsigned int hbackporch_mask;
149 unsigned int field0_vfrontporch_mask;
150 unsigned int field1_vfrontporch_mask;
151 unsigned int field0_vsync_mask;
152 unsigned int field1_vsync_mask;
153 unsigned int field0_vbackporch_mask;
154 unsigned int field1_vbackporch_mask;
Lars-Peter Clausend42010a2013-11-25 15:45:07 -0300155};
156
Hans Verkuil54450f52012-07-18 05:45:16 -0300157/*
158 **********************************************************************
159 *
160 * Arrays with configuration parameters for the ADV7604
161 *
162 **********************************************************************
163 */
Laurent Pinchartc784b1e2014-01-29 10:08:58 -0300164
Pablo Antonb44b2e02015-02-03 14:13:18 -0300165struct adv76xx_state {
166 const struct adv76xx_chip_info *info;
167 struct adv76xx_platform_data pdata;
Laurent Pinchart539b33b2014-01-26 18:42:37 -0300168
Laurent Pincharte9d50e92014-01-30 18:37:08 -0300169 struct gpio_desc *hpd_gpio[4];
Dragos Bogdanf5591da2016-06-22 08:30:42 -0300170 struct gpio_desc *reset_gpio;
Laurent Pincharte9d50e92014-01-30 18:37:08 -0300171
Hans Verkuil54450f52012-07-18 05:45:16 -0300172 struct v4l2_subdev sd;
Pablo Antonb44b2e02015-02-03 14:13:18 -0300173 struct media_pad pads[ADV76XX_PAD_MAX];
Laurent Pinchartc784b1e2014-01-29 10:08:58 -0300174 unsigned int source_pad;
Laurent Pinchart539b33b2014-01-26 18:42:37 -0300175
Hans Verkuil54450f52012-07-18 05:45:16 -0300176 struct v4l2_ctrl_handler hdl;
Laurent Pinchart539b33b2014-01-26 18:42:37 -0300177
Pablo Antonb44b2e02015-02-03 14:13:18 -0300178 enum adv76xx_pad selected_input;
Laurent Pinchart539b33b2014-01-26 18:42:37 -0300179
Hans Verkuil54450f52012-07-18 05:45:16 -0300180 struct v4l2_dv_timings timings;
Pablo Antonb44b2e02015-02-03 14:13:18 -0300181 const struct adv76xx_format_info *format;
Laurent Pinchart539b33b2014-01-26 18:42:37 -0300182
Mats Randgaard4a31a932013-12-10 09:45:00 -0300183 struct {
184 u8 edid[256];
185 u32 present;
186 unsigned blocks;
187 } edid;
Mats Randgaarddd08beb2013-12-10 09:57:09 -0300188 u16 spa_port_a[2];
Hans Verkuil54450f52012-07-18 05:45:16 -0300189 struct v4l2_fract aspect_ratio;
190 u32 rgb_quantization_range;
Hans Verkuil54450f52012-07-18 05:45:16 -0300191 struct delayed_work delayed_work_enable_hotplug;
Hans Verkuilcf9afb12012-10-16 10:12:55 -0300192 bool restart_stdi_once;
Hans Verkuil54450f52012-07-18 05:45:16 -0300193
Mauro Carvalho Chehabcbb5c832016-07-08 18:16:10 -0300194 /* CEC */
Hans Verkuil41a52372015-09-07 08:12:57 -0300195 struct cec_adapter *cec_adap;
196 u8 cec_addr[ADV76XX_MAX_ADDRS];
197 u8 cec_valid_addrs;
198 bool cec_enabled_adap;
199
Hans Verkuil54450f52012-07-18 05:45:16 -0300200 /* i2c clients */
Pablo Antonb44b2e02015-02-03 14:13:18 -0300201 struct i2c_client *i2c_clients[ADV76XX_PAGE_MAX];
Hans Verkuil54450f52012-07-18 05:45:16 -0300202
Pablo Antonf862f572015-06-19 10:23:06 -0300203 /* Regmaps */
204 struct regmap *regmap[ADV76XX_PAGE_MAX];
205
Hans Verkuil54450f52012-07-18 05:45:16 -0300206 /* controls */
207 struct v4l2_ctrl *detect_tx_5v_ctrl;
208 struct v4l2_ctrl *analog_sampling_phase_ctrl;
209 struct v4l2_ctrl *free_run_color_manual_ctrl;
210 struct v4l2_ctrl *free_run_color_ctrl;
211 struct v4l2_ctrl *rgb_quantization_range_ctrl;
212};
213
Pablo Antonb44b2e02015-02-03 14:13:18 -0300214static bool adv76xx_has_afe(struct adv76xx_state *state)
Lars-Peter Clausend42010a2013-11-25 15:45:07 -0300215{
216 return state->info->has_afe;
217}
218
Jean-Michel Hautboisbd3e275f2016-01-27 09:04:50 -0200219/* Unsupported timings. This device cannot support 720p30. */
220static const struct v4l2_dv_timings adv76xx_timings_exceptions[] = {
221 V4L2_DV_BT_CEA_1280X720P30,
222 { }
Hans Verkuil54450f52012-07-18 05:45:16 -0300223};
224
Jean-Michel Hautboisbd3e275f2016-01-27 09:04:50 -0200225static bool adv76xx_check_dv_timings(const struct v4l2_dv_timings *t, void *hdl)
226{
227 int i;
228
229 for (i = 0; adv76xx_timings_exceptions[i].bt.width; i++)
230 if (v4l2_match_dv_timings(t, adv76xx_timings_exceptions + i, 0, false))
231 return false;
232 return true;
233}
234
Pablo Antonb44b2e02015-02-03 14:13:18 -0300235struct adv76xx_video_standards {
Hans Verkuilccbd5bc2012-10-16 10:02:05 -0300236 struct v4l2_dv_timings timings;
237 u8 vid_std;
238 u8 v_freq;
239};
240
241/* sorted by number of lines */
Pablo Antonb44b2e02015-02-03 14:13:18 -0300242static const struct adv76xx_video_standards adv7604_prim_mode_comp[] = {
Hans Verkuilccbd5bc2012-10-16 10:02:05 -0300243 /* { V4L2_DV_BT_CEA_720X480P59_94, 0x0a, 0x00 }, TODO flickering */
244 { V4L2_DV_BT_CEA_720X576P50, 0x0b, 0x00 },
245 { V4L2_DV_BT_CEA_1280X720P50, 0x19, 0x01 },
246 { V4L2_DV_BT_CEA_1280X720P60, 0x19, 0x00 },
247 { V4L2_DV_BT_CEA_1920X1080P24, 0x1e, 0x04 },
248 { V4L2_DV_BT_CEA_1920X1080P25, 0x1e, 0x03 },
249 { V4L2_DV_BT_CEA_1920X1080P30, 0x1e, 0x02 },
250 { V4L2_DV_BT_CEA_1920X1080P50, 0x1e, 0x01 },
251 { V4L2_DV_BT_CEA_1920X1080P60, 0x1e, 0x00 },
252 /* TODO add 1920x1080P60_RB (CVT timing) */
253 { },
254};
255
256/* sorted by number of lines */
Pablo Antonb44b2e02015-02-03 14:13:18 -0300257static const struct adv76xx_video_standards adv7604_prim_mode_gr[] = {
Hans Verkuilccbd5bc2012-10-16 10:02:05 -0300258 { V4L2_DV_BT_DMT_640X480P60, 0x08, 0x00 },
259 { V4L2_DV_BT_DMT_640X480P72, 0x09, 0x00 },
260 { V4L2_DV_BT_DMT_640X480P75, 0x0a, 0x00 },
261 { V4L2_DV_BT_DMT_640X480P85, 0x0b, 0x00 },
262 { V4L2_DV_BT_DMT_800X600P56, 0x00, 0x00 },
263 { V4L2_DV_BT_DMT_800X600P60, 0x01, 0x00 },
264 { V4L2_DV_BT_DMT_800X600P72, 0x02, 0x00 },
265 { V4L2_DV_BT_DMT_800X600P75, 0x03, 0x00 },
266 { V4L2_DV_BT_DMT_800X600P85, 0x04, 0x00 },
267 { V4L2_DV_BT_DMT_1024X768P60, 0x0c, 0x00 },
268 { V4L2_DV_BT_DMT_1024X768P70, 0x0d, 0x00 },
269 { V4L2_DV_BT_DMT_1024X768P75, 0x0e, 0x00 },
270 { V4L2_DV_BT_DMT_1024X768P85, 0x0f, 0x00 },
271 { V4L2_DV_BT_DMT_1280X1024P60, 0x05, 0x00 },
272 { V4L2_DV_BT_DMT_1280X1024P75, 0x06, 0x00 },
273 { V4L2_DV_BT_DMT_1360X768P60, 0x12, 0x00 },
274 { V4L2_DV_BT_DMT_1366X768P60, 0x13, 0x00 },
275 { V4L2_DV_BT_DMT_1400X1050P60, 0x14, 0x00 },
276 { V4L2_DV_BT_DMT_1400X1050P75, 0x15, 0x00 },
277 { V4L2_DV_BT_DMT_1600X1200P60, 0x16, 0x00 }, /* TODO not tested */
278 /* TODO add 1600X1200P60_RB (not a DMT timing) */
279 { V4L2_DV_BT_DMT_1680X1050P60, 0x18, 0x00 },
280 { V4L2_DV_BT_DMT_1920X1200P60_RB, 0x19, 0x00 }, /* TODO not tested */
281 { },
282};
283
284/* sorted by number of lines */
Pablo Antonb44b2e02015-02-03 14:13:18 -0300285static const struct adv76xx_video_standards adv76xx_prim_mode_hdmi_comp[] = {
Hans Verkuilccbd5bc2012-10-16 10:02:05 -0300286 { V4L2_DV_BT_CEA_720X480P59_94, 0x0a, 0x00 },
287 { V4L2_DV_BT_CEA_720X576P50, 0x0b, 0x00 },
288 { V4L2_DV_BT_CEA_1280X720P50, 0x13, 0x01 },
289 { V4L2_DV_BT_CEA_1280X720P60, 0x13, 0x00 },
290 { V4L2_DV_BT_CEA_1920X1080P24, 0x1e, 0x04 },
291 { V4L2_DV_BT_CEA_1920X1080P25, 0x1e, 0x03 },
292 { V4L2_DV_BT_CEA_1920X1080P30, 0x1e, 0x02 },
293 { V4L2_DV_BT_CEA_1920X1080P50, 0x1e, 0x01 },
294 { V4L2_DV_BT_CEA_1920X1080P60, 0x1e, 0x00 },
295 { },
296};
297
298/* sorted by number of lines */
Pablo Antonb44b2e02015-02-03 14:13:18 -0300299static const struct adv76xx_video_standards adv76xx_prim_mode_hdmi_gr[] = {
Hans Verkuilccbd5bc2012-10-16 10:02:05 -0300300 { V4L2_DV_BT_DMT_640X480P60, 0x08, 0x00 },
301 { V4L2_DV_BT_DMT_640X480P72, 0x09, 0x00 },
302 { V4L2_DV_BT_DMT_640X480P75, 0x0a, 0x00 },
303 { V4L2_DV_BT_DMT_640X480P85, 0x0b, 0x00 },
304 { V4L2_DV_BT_DMT_800X600P56, 0x00, 0x00 },
305 { V4L2_DV_BT_DMT_800X600P60, 0x01, 0x00 },
306 { V4L2_DV_BT_DMT_800X600P72, 0x02, 0x00 },
307 { V4L2_DV_BT_DMT_800X600P75, 0x03, 0x00 },
308 { V4L2_DV_BT_DMT_800X600P85, 0x04, 0x00 },
309 { V4L2_DV_BT_DMT_1024X768P60, 0x0c, 0x00 },
310 { V4L2_DV_BT_DMT_1024X768P70, 0x0d, 0x00 },
311 { V4L2_DV_BT_DMT_1024X768P75, 0x0e, 0x00 },
312 { V4L2_DV_BT_DMT_1024X768P85, 0x0f, 0x00 },
313 { V4L2_DV_BT_DMT_1280X1024P60, 0x05, 0x00 },
314 { V4L2_DV_BT_DMT_1280X1024P75, 0x06, 0x00 },
315 { },
316};
317
Hans Verkuil48519832015-05-07 10:37:57 -0300318static const struct v4l2_event adv76xx_ev_fmt = {
319 .type = V4L2_EVENT_SOURCE_CHANGE,
320 .u.src_change.changes = V4L2_EVENT_SRC_CH_RESOLUTION,
321};
322
Hans Verkuil54450f52012-07-18 05:45:16 -0300323/* ----------------------------------------------------------------------- */
324
Pablo Antonb44b2e02015-02-03 14:13:18 -0300325static inline struct adv76xx_state *to_state(struct v4l2_subdev *sd)
Hans Verkuil54450f52012-07-18 05:45:16 -0300326{
Pablo Antonb44b2e02015-02-03 14:13:18 -0300327 return container_of(sd, struct adv76xx_state, sd);
Hans Verkuil54450f52012-07-18 05:45:16 -0300328}
329
Hans Verkuil54450f52012-07-18 05:45:16 -0300330static inline unsigned htotal(const struct v4l2_bt_timings *t)
331{
Hans Verkuileacf8f92013-07-29 08:40:59 -0300332 return V4L2_DV_BT_FRAME_WIDTH(t);
Hans Verkuil54450f52012-07-18 05:45:16 -0300333}
334
Hans Verkuil54450f52012-07-18 05:45:16 -0300335static inline unsigned vtotal(const struct v4l2_bt_timings *t)
336{
Hans Verkuileacf8f92013-07-29 08:40:59 -0300337 return V4L2_DV_BT_FRAME_HEIGHT(t);
Hans Verkuil54450f52012-07-18 05:45:16 -0300338}
339
340/* ----------------------------------------------------------------------- */
341
Pablo Antonf862f572015-06-19 10:23:06 -0300342static int adv76xx_read_check(struct adv76xx_state *state,
343 int client_page, u8 reg)
Hans Verkuil54450f52012-07-18 05:45:16 -0300344{
Pablo Antonf862f572015-06-19 10:23:06 -0300345 struct i2c_client *client = state->i2c_clients[client_page];
Hans Verkuil54450f52012-07-18 05:45:16 -0300346 int err;
Pablo Antonf862f572015-06-19 10:23:06 -0300347 unsigned int val;
Hans Verkuil54450f52012-07-18 05:45:16 -0300348
Pablo Antonf862f572015-06-19 10:23:06 -0300349 err = regmap_read(state->regmap[client_page], reg, &val);
350
351 if (err) {
352 v4l_err(client, "error reading %02x, %02x\n",
353 client->addr, reg);
354 return err;
Hans Verkuil54450f52012-07-18 05:45:16 -0300355 }
Pablo Antonf862f572015-06-19 10:23:06 -0300356 return val;
Hans Verkuil54450f52012-07-18 05:45:16 -0300357}
358
Pablo Antonf862f572015-06-19 10:23:06 -0300359/* adv76xx_write_block(): Write raw data with a maximum of I2C_SMBUS_BLOCK_MAX
360 * size to one or more registers.
361 *
362 * A value of zero will be returned on success, a negative errno will
363 * be returned in error cases.
364 */
365static int adv76xx_write_block(struct adv76xx_state *state, int client_page,
366 unsigned int init_reg, const void *val,
367 size_t val_len)
Hans Verkuil54450f52012-07-18 05:45:16 -0300368{
Pablo Antonf862f572015-06-19 10:23:06 -0300369 struct regmap *regmap = state->regmap[client_page];
Hans Verkuil54450f52012-07-18 05:45:16 -0300370
Pablo Antonf862f572015-06-19 10:23:06 -0300371 if (val_len > I2C_SMBUS_BLOCK_MAX)
372 val_len = I2C_SMBUS_BLOCK_MAX;
373
374 return regmap_raw_write(regmap, init_reg, val, val_len);
Hans Verkuil54450f52012-07-18 05:45:16 -0300375}
376
377/* ----------------------------------------------------------------------- */
378
379static inline int io_read(struct v4l2_subdev *sd, u8 reg)
380{
Pablo Antonb44b2e02015-02-03 14:13:18 -0300381 struct adv76xx_state *state = to_state(sd);
Hans Verkuil54450f52012-07-18 05:45:16 -0300382
Pablo Antonf862f572015-06-19 10:23:06 -0300383 return adv76xx_read_check(state, ADV76XX_PAGE_IO, reg);
Hans Verkuil54450f52012-07-18 05:45:16 -0300384}
385
386static inline int io_write(struct v4l2_subdev *sd, u8 reg, u8 val)
387{
Pablo Antonb44b2e02015-02-03 14:13:18 -0300388 struct adv76xx_state *state = to_state(sd);
Hans Verkuil54450f52012-07-18 05:45:16 -0300389
Pablo Antonf862f572015-06-19 10:23:06 -0300390 return regmap_write(state->regmap[ADV76XX_PAGE_IO], reg, val);
Hans Verkuil54450f52012-07-18 05:45:16 -0300391}
392
Hans Verkuil41a52372015-09-07 08:12:57 -0300393static inline int io_write_clr_set(struct v4l2_subdev *sd, u8 reg, u8 mask,
394 u8 val)
Hans Verkuil54450f52012-07-18 05:45:16 -0300395{
Laurent Pinchart22d97e52014-01-30 17:17:42 -0300396 return io_write(sd, reg, (io_read(sd, reg) & ~mask) | val);
Hans Verkuil54450f52012-07-18 05:45:16 -0300397}
398
399static inline int avlink_read(struct v4l2_subdev *sd, u8 reg)
400{
Pablo Antonb44b2e02015-02-03 14:13:18 -0300401 struct adv76xx_state *state = to_state(sd);
Hans Verkuil54450f52012-07-18 05:45:16 -0300402
Pablo Antonf862f572015-06-19 10:23:06 -0300403 return adv76xx_read_check(state, ADV7604_PAGE_AVLINK, reg);
Hans Verkuil54450f52012-07-18 05:45:16 -0300404}
405
406static inline int avlink_write(struct v4l2_subdev *sd, u8 reg, u8 val)
407{
Pablo Antonb44b2e02015-02-03 14:13:18 -0300408 struct adv76xx_state *state = to_state(sd);
Hans Verkuil54450f52012-07-18 05:45:16 -0300409
Pablo Antonf862f572015-06-19 10:23:06 -0300410 return regmap_write(state->regmap[ADV7604_PAGE_AVLINK], reg, val);
Hans Verkuil54450f52012-07-18 05:45:16 -0300411}
412
413static inline int cec_read(struct v4l2_subdev *sd, u8 reg)
414{
Pablo Antonb44b2e02015-02-03 14:13:18 -0300415 struct adv76xx_state *state = to_state(sd);
Hans Verkuil54450f52012-07-18 05:45:16 -0300416
Pablo Antonf862f572015-06-19 10:23:06 -0300417 return adv76xx_read_check(state, ADV76XX_PAGE_CEC, reg);
Hans Verkuil54450f52012-07-18 05:45:16 -0300418}
419
420static inline int cec_write(struct v4l2_subdev *sd, u8 reg, u8 val)
421{
Pablo Antonb44b2e02015-02-03 14:13:18 -0300422 struct adv76xx_state *state = to_state(sd);
Hans Verkuil54450f52012-07-18 05:45:16 -0300423
Pablo Antonf862f572015-06-19 10:23:06 -0300424 return regmap_write(state->regmap[ADV76XX_PAGE_CEC], reg, val);
Hans Verkuil54450f52012-07-18 05:45:16 -0300425}
426
Hans Verkuil41a52372015-09-07 08:12:57 -0300427static inline int cec_write_clr_set(struct v4l2_subdev *sd, u8 reg, u8 mask,
428 u8 val)
429{
430 return cec_write(sd, reg, (cec_read(sd, reg) & ~mask) | val);
431}
432
Hans Verkuil54450f52012-07-18 05:45:16 -0300433static inline int infoframe_read(struct v4l2_subdev *sd, u8 reg)
434{
Pablo Antonb44b2e02015-02-03 14:13:18 -0300435 struct adv76xx_state *state = to_state(sd);
Hans Verkuil54450f52012-07-18 05:45:16 -0300436
Pablo Antonf862f572015-06-19 10:23:06 -0300437 return adv76xx_read_check(state, ADV76XX_PAGE_INFOFRAME, reg);
Hans Verkuil54450f52012-07-18 05:45:16 -0300438}
439
440static inline int infoframe_write(struct v4l2_subdev *sd, u8 reg, u8 val)
441{
Pablo Antonb44b2e02015-02-03 14:13:18 -0300442 struct adv76xx_state *state = to_state(sd);
Hans Verkuil54450f52012-07-18 05:45:16 -0300443
Pablo Antonf862f572015-06-19 10:23:06 -0300444 return regmap_write(state->regmap[ADV76XX_PAGE_INFOFRAME], reg, val);
Hans Verkuil54450f52012-07-18 05:45:16 -0300445}
446
Hans Verkuil54450f52012-07-18 05:45:16 -0300447static inline int afe_read(struct v4l2_subdev *sd, u8 reg)
448{
Pablo Antonb44b2e02015-02-03 14:13:18 -0300449 struct adv76xx_state *state = to_state(sd);
Hans Verkuil54450f52012-07-18 05:45:16 -0300450
Pablo Antonf862f572015-06-19 10:23:06 -0300451 return adv76xx_read_check(state, ADV76XX_PAGE_AFE, reg);
Hans Verkuil54450f52012-07-18 05:45:16 -0300452}
453
454static inline int afe_write(struct v4l2_subdev *sd, u8 reg, u8 val)
455{
Pablo Antonb44b2e02015-02-03 14:13:18 -0300456 struct adv76xx_state *state = to_state(sd);
Hans Verkuil54450f52012-07-18 05:45:16 -0300457
Pablo Antonf862f572015-06-19 10:23:06 -0300458 return regmap_write(state->regmap[ADV76XX_PAGE_AFE], reg, val);
Hans Verkuil54450f52012-07-18 05:45:16 -0300459}
460
461static inline int rep_read(struct v4l2_subdev *sd, u8 reg)
462{
Pablo Antonb44b2e02015-02-03 14:13:18 -0300463 struct adv76xx_state *state = to_state(sd);
Hans Verkuil54450f52012-07-18 05:45:16 -0300464
Pablo Antonf862f572015-06-19 10:23:06 -0300465 return adv76xx_read_check(state, ADV76XX_PAGE_REP, reg);
Hans Verkuil54450f52012-07-18 05:45:16 -0300466}
467
468static inline int rep_write(struct v4l2_subdev *sd, u8 reg, u8 val)
469{
Pablo Antonb44b2e02015-02-03 14:13:18 -0300470 struct adv76xx_state *state = to_state(sd);
Hans Verkuil54450f52012-07-18 05:45:16 -0300471
Pablo Antonf862f572015-06-19 10:23:06 -0300472 return regmap_write(state->regmap[ADV76XX_PAGE_REP], reg, val);
Hans Verkuil54450f52012-07-18 05:45:16 -0300473}
474
Laurent Pinchart22d97e52014-01-30 17:17:42 -0300475static inline int rep_write_clr_set(struct v4l2_subdev *sd, u8 reg, u8 mask, u8 val)
Hans Verkuil54450f52012-07-18 05:45:16 -0300476{
Laurent Pinchart22d97e52014-01-30 17:17:42 -0300477 return rep_write(sd, reg, (rep_read(sd, reg) & ~mask) | val);
Hans Verkuil54450f52012-07-18 05:45:16 -0300478}
479
480static inline int edid_read(struct v4l2_subdev *sd, u8 reg)
481{
Pablo Antonb44b2e02015-02-03 14:13:18 -0300482 struct adv76xx_state *state = to_state(sd);
Hans Verkuil54450f52012-07-18 05:45:16 -0300483
Pablo Antonf862f572015-06-19 10:23:06 -0300484 return adv76xx_read_check(state, ADV76XX_PAGE_EDID, reg);
Hans Verkuil54450f52012-07-18 05:45:16 -0300485}
486
487static inline int edid_write(struct v4l2_subdev *sd, u8 reg, u8 val)
488{
Pablo Antonb44b2e02015-02-03 14:13:18 -0300489 struct adv76xx_state *state = to_state(sd);
Hans Verkuil54450f52012-07-18 05:45:16 -0300490
Pablo Antonf862f572015-06-19 10:23:06 -0300491 return regmap_write(state->regmap[ADV76XX_PAGE_EDID], reg, val);
Hans Verkuil54450f52012-07-18 05:45:16 -0300492}
493
Mats Randgaarddd08beb2013-12-10 09:57:09 -0300494static inline int edid_write_block(struct v4l2_subdev *sd,
Pablo Antonf862f572015-06-19 10:23:06 -0300495 unsigned int total_len, const u8 *val)
Mats Randgaarddd08beb2013-12-10 09:57:09 -0300496{
Pablo Antonb44b2e02015-02-03 14:13:18 -0300497 struct adv76xx_state *state = to_state(sd);
Mats Randgaarddd08beb2013-12-10 09:57:09 -0300498 int err = 0;
Pablo Antonf862f572015-06-19 10:23:06 -0300499 int i = 0;
500 int len = 0;
Mats Randgaarddd08beb2013-12-10 09:57:09 -0300501
Pablo Antonf862f572015-06-19 10:23:06 -0300502 v4l2_dbg(2, debug, sd, "%s: write EDID block (%d byte)\n",
503 __func__, total_len);
Mats Randgaarddd08beb2013-12-10 09:57:09 -0300504
Pablo Antonf862f572015-06-19 10:23:06 -0300505 while (!err && i < total_len) {
506 len = (total_len - i) > I2C_SMBUS_BLOCK_MAX ?
507 I2C_SMBUS_BLOCK_MAX :
508 (total_len - i);
509
510 err = adv76xx_write_block(state, ADV76XX_PAGE_EDID,
511 i, val + i, len);
512 i += len;
513 }
514
Mats Randgaarddd08beb2013-12-10 09:57:09 -0300515 return err;
516}
517
Pablo Antonb44b2e02015-02-03 14:13:18 -0300518static void adv76xx_set_hpd(struct adv76xx_state *state, unsigned int hpd)
Laurent Pincharte9d50e92014-01-30 18:37:08 -0300519{
520 unsigned int i;
521
Uwe Kleine-König269bd132015-03-02 04:00:44 -0300522 for (i = 0; i < state->info->num_dv_ports; ++i)
Laurent Pincharte9d50e92014-01-30 18:37:08 -0300523 gpiod_set_value_cansleep(state->hpd_gpio[i], hpd & BIT(i));
Laurent Pincharte9d50e92014-01-30 18:37:08 -0300524
Pablo Antonb44b2e02015-02-03 14:13:18 -0300525 v4l2_subdev_notify(&state->sd, ADV76XX_HOTPLUG, &hpd);
Laurent Pincharte9d50e92014-01-30 18:37:08 -0300526}
527
Pablo Antonb44b2e02015-02-03 14:13:18 -0300528static void adv76xx_delayed_work_enable_hotplug(struct work_struct *work)
Hans Verkuil54450f52012-07-18 05:45:16 -0300529{
530 struct delayed_work *dwork = to_delayed_work(work);
Pablo Antonb44b2e02015-02-03 14:13:18 -0300531 struct adv76xx_state *state = container_of(dwork, struct adv76xx_state,
Hans Verkuil54450f52012-07-18 05:45:16 -0300532 delayed_work_enable_hotplug);
533 struct v4l2_subdev *sd = &state->sd;
534
535 v4l2_dbg(2, debug, sd, "%s: enable hotplug\n", __func__);
536
Pablo Antonb44b2e02015-02-03 14:13:18 -0300537 adv76xx_set_hpd(state, state->edid.present);
Hans Verkuil54450f52012-07-18 05:45:16 -0300538}
539
Hans Verkuil54450f52012-07-18 05:45:16 -0300540static inline int hdmi_read(struct v4l2_subdev *sd, u8 reg)
541{
Pablo Antonb44b2e02015-02-03 14:13:18 -0300542 struct adv76xx_state *state = to_state(sd);
Hans Verkuil54450f52012-07-18 05:45:16 -0300543
Pablo Antonf862f572015-06-19 10:23:06 -0300544 return adv76xx_read_check(state, ADV76XX_PAGE_HDMI, reg);
Hans Verkuil54450f52012-07-18 05:45:16 -0300545}
546
Laurent Pinchart51182a92014-01-08 19:30:37 -0300547static u16 hdmi_read16(struct v4l2_subdev *sd, u8 reg, u16 mask)
548{
549 return ((hdmi_read(sd, reg) << 8) | hdmi_read(sd, reg + 1)) & mask;
550}
551
Hans Verkuil54450f52012-07-18 05:45:16 -0300552static inline int hdmi_write(struct v4l2_subdev *sd, u8 reg, u8 val)
553{
Pablo Antonb44b2e02015-02-03 14:13:18 -0300554 struct adv76xx_state *state = to_state(sd);
Hans Verkuil54450f52012-07-18 05:45:16 -0300555
Pablo Antonf862f572015-06-19 10:23:06 -0300556 return regmap_write(state->regmap[ADV76XX_PAGE_HDMI], reg, val);
Hans Verkuil54450f52012-07-18 05:45:16 -0300557}
558
Laurent Pinchart22d97e52014-01-30 17:17:42 -0300559static inline int hdmi_write_clr_set(struct v4l2_subdev *sd, u8 reg, u8 mask, u8 val)
Mats Randgaard4a31a932013-12-10 09:45:00 -0300560{
Laurent Pinchart22d97e52014-01-30 17:17:42 -0300561 return hdmi_write(sd, reg, (hdmi_read(sd, reg) & ~mask) | val);
Mats Randgaard4a31a932013-12-10 09:45:00 -0300562}
563
Hans Verkuil54450f52012-07-18 05:45:16 -0300564static inline int test_write(struct v4l2_subdev *sd, u8 reg, u8 val)
565{
Pablo Antonb44b2e02015-02-03 14:13:18 -0300566 struct adv76xx_state *state = to_state(sd);
Hans Verkuil54450f52012-07-18 05:45:16 -0300567
Pablo Antonf862f572015-06-19 10:23:06 -0300568 return regmap_write(state->regmap[ADV76XX_PAGE_TEST], reg, val);
Hans Verkuil54450f52012-07-18 05:45:16 -0300569}
570
571static inline int cp_read(struct v4l2_subdev *sd, u8 reg)
572{
Pablo Antonb44b2e02015-02-03 14:13:18 -0300573 struct adv76xx_state *state = to_state(sd);
Hans Verkuil54450f52012-07-18 05:45:16 -0300574
Pablo Antonf862f572015-06-19 10:23:06 -0300575 return adv76xx_read_check(state, ADV76XX_PAGE_CP, reg);
Hans Verkuil54450f52012-07-18 05:45:16 -0300576}
577
Laurent Pinchart51182a92014-01-08 19:30:37 -0300578static u16 cp_read16(struct v4l2_subdev *sd, u8 reg, u16 mask)
579{
580 return ((cp_read(sd, reg) << 8) | cp_read(sd, reg + 1)) & mask;
581}
582
Hans Verkuil54450f52012-07-18 05:45:16 -0300583static inline int cp_write(struct v4l2_subdev *sd, u8 reg, u8 val)
584{
Pablo Antonb44b2e02015-02-03 14:13:18 -0300585 struct adv76xx_state *state = to_state(sd);
Hans Verkuil54450f52012-07-18 05:45:16 -0300586
Pablo Antonf862f572015-06-19 10:23:06 -0300587 return regmap_write(state->regmap[ADV76XX_PAGE_CP], reg, val);
Hans Verkuil54450f52012-07-18 05:45:16 -0300588}
589
Laurent Pinchart22d97e52014-01-30 17:17:42 -0300590static inline int cp_write_clr_set(struct v4l2_subdev *sd, u8 reg, u8 mask, u8 val)
Hans Verkuil54450f52012-07-18 05:45:16 -0300591{
Laurent Pinchart22d97e52014-01-30 17:17:42 -0300592 return cp_write(sd, reg, (cp_read(sd, reg) & ~mask) | val);
Hans Verkuil54450f52012-07-18 05:45:16 -0300593}
594
595static inline int vdp_read(struct v4l2_subdev *sd, u8 reg)
596{
Pablo Antonb44b2e02015-02-03 14:13:18 -0300597 struct adv76xx_state *state = to_state(sd);
Hans Verkuil54450f52012-07-18 05:45:16 -0300598
Pablo Antonf862f572015-06-19 10:23:06 -0300599 return adv76xx_read_check(state, ADV7604_PAGE_VDP, reg);
Hans Verkuil54450f52012-07-18 05:45:16 -0300600}
601
602static inline int vdp_write(struct v4l2_subdev *sd, u8 reg, u8 val)
603{
Pablo Antonb44b2e02015-02-03 14:13:18 -0300604 struct adv76xx_state *state = to_state(sd);
Hans Verkuil54450f52012-07-18 05:45:16 -0300605
Pablo Antonf862f572015-06-19 10:23:06 -0300606 return regmap_write(state->regmap[ADV7604_PAGE_VDP], reg, val);
Hans Verkuil54450f52012-07-18 05:45:16 -0300607}
608
Pablo Antonb44b2e02015-02-03 14:13:18 -0300609#define ADV76XX_REG(page, offset) (((page) << 8) | (offset))
610#define ADV76XX_REG_SEQ_TERM 0xffff
Lars-Peter Clausend42010a2013-11-25 15:45:07 -0300611
612#ifdef CONFIG_VIDEO_ADV_DEBUG
Pablo Antonb44b2e02015-02-03 14:13:18 -0300613static int adv76xx_read_reg(struct v4l2_subdev *sd, unsigned int reg)
Lars-Peter Clausend42010a2013-11-25 15:45:07 -0300614{
Pablo Antonb44b2e02015-02-03 14:13:18 -0300615 struct adv76xx_state *state = to_state(sd);
Lars-Peter Clausend42010a2013-11-25 15:45:07 -0300616 unsigned int page = reg >> 8;
Pablo Antonf862f572015-06-19 10:23:06 -0300617 unsigned int val;
618 int err;
Lars-Peter Clausend42010a2013-11-25 15:45:07 -0300619
620 if (!(BIT(page) & state->info->page_mask))
621 return -EINVAL;
622
623 reg &= 0xff;
Pablo Antonf862f572015-06-19 10:23:06 -0300624 err = regmap_read(state->regmap[page], reg, &val);
Lars-Peter Clausend42010a2013-11-25 15:45:07 -0300625
Pablo Antonf862f572015-06-19 10:23:06 -0300626 return err ? err : val;
Lars-Peter Clausend42010a2013-11-25 15:45:07 -0300627}
628#endif
629
Pablo Antonb44b2e02015-02-03 14:13:18 -0300630static int adv76xx_write_reg(struct v4l2_subdev *sd, unsigned int reg, u8 val)
Lars-Peter Clausend42010a2013-11-25 15:45:07 -0300631{
Pablo Antonb44b2e02015-02-03 14:13:18 -0300632 struct adv76xx_state *state = to_state(sd);
Lars-Peter Clausend42010a2013-11-25 15:45:07 -0300633 unsigned int page = reg >> 8;
634
635 if (!(BIT(page) & state->info->page_mask))
636 return -EINVAL;
637
638 reg &= 0xff;
639
Pablo Antonf862f572015-06-19 10:23:06 -0300640 return regmap_write(state->regmap[page], reg, val);
Lars-Peter Clausend42010a2013-11-25 15:45:07 -0300641}
642
Pablo Antonb44b2e02015-02-03 14:13:18 -0300643static void adv76xx_write_reg_seq(struct v4l2_subdev *sd,
644 const struct adv76xx_reg_seq *reg_seq)
Lars-Peter Clausend42010a2013-11-25 15:45:07 -0300645{
646 unsigned int i;
647
Pablo Antonb44b2e02015-02-03 14:13:18 -0300648 for (i = 0; reg_seq[i].reg != ADV76XX_REG_SEQ_TERM; i++)
649 adv76xx_write_reg(sd, reg_seq[i].reg, reg_seq[i].val);
Lars-Peter Clausend42010a2013-11-25 15:45:07 -0300650}
651
Laurent Pinchart539b33b2014-01-26 18:42:37 -0300652/* -----------------------------------------------------------------------------
653 * Format helpers
654 */
655
Pablo Antonb44b2e02015-02-03 14:13:18 -0300656static const struct adv76xx_format_info adv7604_formats[] = {
657 { MEDIA_BUS_FMT_RGB888_1X24, ADV76XX_OP_CH_SEL_RGB, true, false,
658 ADV76XX_OP_MODE_SEL_SDR_444 | ADV76XX_OP_FORMAT_SEL_8BIT },
659 { MEDIA_BUS_FMT_YUYV8_2X8, ADV76XX_OP_CH_SEL_RGB, false, false,
660 ADV76XX_OP_MODE_SEL_SDR_422 | ADV76XX_OP_FORMAT_SEL_8BIT },
661 { MEDIA_BUS_FMT_YVYU8_2X8, ADV76XX_OP_CH_SEL_RGB, false, true,
662 ADV76XX_OP_MODE_SEL_SDR_422 | ADV76XX_OP_FORMAT_SEL_8BIT },
663 { MEDIA_BUS_FMT_YUYV10_2X10, ADV76XX_OP_CH_SEL_RGB, false, false,
664 ADV76XX_OP_MODE_SEL_SDR_422 | ADV7604_OP_FORMAT_SEL_10BIT },
665 { MEDIA_BUS_FMT_YVYU10_2X10, ADV76XX_OP_CH_SEL_RGB, false, true,
666 ADV76XX_OP_MODE_SEL_SDR_422 | ADV7604_OP_FORMAT_SEL_10BIT },
667 { MEDIA_BUS_FMT_YUYV12_2X12, ADV76XX_OP_CH_SEL_RGB, false, false,
668 ADV76XX_OP_MODE_SEL_SDR_422 | ADV76XX_OP_FORMAT_SEL_12BIT },
669 { MEDIA_BUS_FMT_YVYU12_2X12, ADV76XX_OP_CH_SEL_RGB, false, true,
670 ADV76XX_OP_MODE_SEL_SDR_422 | ADV76XX_OP_FORMAT_SEL_12BIT },
671 { MEDIA_BUS_FMT_UYVY8_1X16, ADV76XX_OP_CH_SEL_RBG, false, false,
672 ADV76XX_OP_MODE_SEL_SDR_422_2X | ADV76XX_OP_FORMAT_SEL_8BIT },
673 { MEDIA_BUS_FMT_VYUY8_1X16, ADV76XX_OP_CH_SEL_RBG, false, true,
674 ADV76XX_OP_MODE_SEL_SDR_422_2X | ADV76XX_OP_FORMAT_SEL_8BIT },
675 { MEDIA_BUS_FMT_YUYV8_1X16, ADV76XX_OP_CH_SEL_RGB, false, false,
676 ADV76XX_OP_MODE_SEL_SDR_422_2X | ADV76XX_OP_FORMAT_SEL_8BIT },
677 { MEDIA_BUS_FMT_YVYU8_1X16, ADV76XX_OP_CH_SEL_RGB, false, true,
678 ADV76XX_OP_MODE_SEL_SDR_422_2X | ADV76XX_OP_FORMAT_SEL_8BIT },
679 { MEDIA_BUS_FMT_UYVY10_1X20, ADV76XX_OP_CH_SEL_RBG, false, false,
680 ADV76XX_OP_MODE_SEL_SDR_422_2X | ADV7604_OP_FORMAT_SEL_10BIT },
681 { MEDIA_BUS_FMT_VYUY10_1X20, ADV76XX_OP_CH_SEL_RBG, false, true,
682 ADV76XX_OP_MODE_SEL_SDR_422_2X | ADV7604_OP_FORMAT_SEL_10BIT },
683 { MEDIA_BUS_FMT_YUYV10_1X20, ADV76XX_OP_CH_SEL_RGB, false, false,
684 ADV76XX_OP_MODE_SEL_SDR_422_2X | ADV7604_OP_FORMAT_SEL_10BIT },
685 { MEDIA_BUS_FMT_YVYU10_1X20, ADV76XX_OP_CH_SEL_RGB, false, true,
686 ADV76XX_OP_MODE_SEL_SDR_422_2X | ADV7604_OP_FORMAT_SEL_10BIT },
687 { MEDIA_BUS_FMT_UYVY12_1X24, ADV76XX_OP_CH_SEL_RBG, false, false,
688 ADV76XX_OP_MODE_SEL_SDR_422_2X | ADV76XX_OP_FORMAT_SEL_12BIT },
689 { MEDIA_BUS_FMT_VYUY12_1X24, ADV76XX_OP_CH_SEL_RBG, false, true,
690 ADV76XX_OP_MODE_SEL_SDR_422_2X | ADV76XX_OP_FORMAT_SEL_12BIT },
691 { MEDIA_BUS_FMT_YUYV12_1X24, ADV76XX_OP_CH_SEL_RGB, false, false,
692 ADV76XX_OP_MODE_SEL_SDR_422_2X | ADV76XX_OP_FORMAT_SEL_12BIT },
693 { MEDIA_BUS_FMT_YVYU12_1X24, ADV76XX_OP_CH_SEL_RGB, false, true,
694 ADV76XX_OP_MODE_SEL_SDR_422_2X | ADV76XX_OP_FORMAT_SEL_12BIT },
Laurent Pinchart539b33b2014-01-26 18:42:37 -0300695};
696
Pablo Antonb44b2e02015-02-03 14:13:18 -0300697static const struct adv76xx_format_info adv7611_formats[] = {
698 { MEDIA_BUS_FMT_RGB888_1X24, ADV76XX_OP_CH_SEL_RGB, true, false,
699 ADV76XX_OP_MODE_SEL_SDR_444 | ADV76XX_OP_FORMAT_SEL_8BIT },
700 { MEDIA_BUS_FMT_YUYV8_2X8, ADV76XX_OP_CH_SEL_RGB, false, false,
701 ADV76XX_OP_MODE_SEL_SDR_422 | ADV76XX_OP_FORMAT_SEL_8BIT },
702 { MEDIA_BUS_FMT_YVYU8_2X8, ADV76XX_OP_CH_SEL_RGB, false, true,
703 ADV76XX_OP_MODE_SEL_SDR_422 | ADV76XX_OP_FORMAT_SEL_8BIT },
704 { MEDIA_BUS_FMT_YUYV12_2X12, ADV76XX_OP_CH_SEL_RGB, false, false,
705 ADV76XX_OP_MODE_SEL_SDR_422 | ADV76XX_OP_FORMAT_SEL_12BIT },
706 { MEDIA_BUS_FMT_YVYU12_2X12, ADV76XX_OP_CH_SEL_RGB, false, true,
707 ADV76XX_OP_MODE_SEL_SDR_422 | ADV76XX_OP_FORMAT_SEL_12BIT },
708 { MEDIA_BUS_FMT_UYVY8_1X16, ADV76XX_OP_CH_SEL_RBG, false, false,
709 ADV76XX_OP_MODE_SEL_SDR_422_2X | ADV76XX_OP_FORMAT_SEL_8BIT },
710 { MEDIA_BUS_FMT_VYUY8_1X16, ADV76XX_OP_CH_SEL_RBG, false, true,
711 ADV76XX_OP_MODE_SEL_SDR_422_2X | ADV76XX_OP_FORMAT_SEL_8BIT },
712 { MEDIA_BUS_FMT_YUYV8_1X16, ADV76XX_OP_CH_SEL_RGB, false, false,
713 ADV76XX_OP_MODE_SEL_SDR_422_2X | ADV76XX_OP_FORMAT_SEL_8BIT },
714 { MEDIA_BUS_FMT_YVYU8_1X16, ADV76XX_OP_CH_SEL_RGB, false, true,
715 ADV76XX_OP_MODE_SEL_SDR_422_2X | ADV76XX_OP_FORMAT_SEL_8BIT },
716 { MEDIA_BUS_FMT_UYVY12_1X24, ADV76XX_OP_CH_SEL_RBG, false, false,
717 ADV76XX_OP_MODE_SEL_SDR_422_2X | ADV76XX_OP_FORMAT_SEL_12BIT },
718 { MEDIA_BUS_FMT_VYUY12_1X24, ADV76XX_OP_CH_SEL_RBG, false, true,
719 ADV76XX_OP_MODE_SEL_SDR_422_2X | ADV76XX_OP_FORMAT_SEL_12BIT },
720 { MEDIA_BUS_FMT_YUYV12_1X24, ADV76XX_OP_CH_SEL_RGB, false, false,
721 ADV76XX_OP_MODE_SEL_SDR_422_2X | ADV76XX_OP_FORMAT_SEL_12BIT },
722 { MEDIA_BUS_FMT_YVYU12_1X24, ADV76XX_OP_CH_SEL_RGB, false, true,
723 ADV76XX_OP_MODE_SEL_SDR_422_2X | ADV76XX_OP_FORMAT_SEL_12BIT },
Laurent Pinchart539b33b2014-01-26 18:42:37 -0300724};
725
William Towle8331d302015-06-03 10:59:51 -0300726static const struct adv76xx_format_info adv7612_formats[] = {
727 { MEDIA_BUS_FMT_RGB888_1X24, ADV76XX_OP_CH_SEL_RGB, true, false,
728 ADV76XX_OP_MODE_SEL_SDR_444 | ADV76XX_OP_FORMAT_SEL_8BIT },
729 { MEDIA_BUS_FMT_YUYV8_2X8, ADV76XX_OP_CH_SEL_RGB, false, false,
730 ADV76XX_OP_MODE_SEL_SDR_422 | ADV76XX_OP_FORMAT_SEL_8BIT },
731 { MEDIA_BUS_FMT_YVYU8_2X8, ADV76XX_OP_CH_SEL_RGB, false, true,
732 ADV76XX_OP_MODE_SEL_SDR_422 | ADV76XX_OP_FORMAT_SEL_8BIT },
733 { MEDIA_BUS_FMT_UYVY8_1X16, ADV76XX_OP_CH_SEL_RBG, false, false,
734 ADV76XX_OP_MODE_SEL_SDR_422_2X | ADV76XX_OP_FORMAT_SEL_8BIT },
735 { MEDIA_BUS_FMT_VYUY8_1X16, ADV76XX_OP_CH_SEL_RBG, false, true,
736 ADV76XX_OP_MODE_SEL_SDR_422_2X | ADV76XX_OP_FORMAT_SEL_8BIT },
737 { MEDIA_BUS_FMT_YUYV8_1X16, ADV76XX_OP_CH_SEL_RGB, false, false,
738 ADV76XX_OP_MODE_SEL_SDR_422_2X | ADV76XX_OP_FORMAT_SEL_8BIT },
739 { MEDIA_BUS_FMT_YVYU8_1X16, ADV76XX_OP_CH_SEL_RGB, false, true,
740 ADV76XX_OP_MODE_SEL_SDR_422_2X | ADV76XX_OP_FORMAT_SEL_8BIT },
741};
742
Pablo Antonb44b2e02015-02-03 14:13:18 -0300743static const struct adv76xx_format_info *
744adv76xx_format_info(struct adv76xx_state *state, u32 code)
Laurent Pinchart539b33b2014-01-26 18:42:37 -0300745{
746 unsigned int i;
747
748 for (i = 0; i < state->info->nformats; ++i) {
749 if (state->info->formats[i].code == code)
750 return &state->info->formats[i];
751 }
752
753 return NULL;
754}
755
Hans Verkuil54450f52012-07-18 05:45:16 -0300756/* ----------------------------------------------------------------------- */
757
Mats Randgaard4a31a932013-12-10 09:45:00 -0300758static inline bool is_analog_input(struct v4l2_subdev *sd)
759{
Pablo Antonb44b2e02015-02-03 14:13:18 -0300760 struct adv76xx_state *state = to_state(sd);
Mats Randgaard4a31a932013-12-10 09:45:00 -0300761
Laurent Pinchartc784b1e2014-01-29 10:08:58 -0300762 return state->selected_input == ADV7604_PAD_VGA_RGB ||
763 state->selected_input == ADV7604_PAD_VGA_COMP;
Mats Randgaard4a31a932013-12-10 09:45:00 -0300764}
765
766static inline bool is_digital_input(struct v4l2_subdev *sd)
767{
Pablo Antonb44b2e02015-02-03 14:13:18 -0300768 struct adv76xx_state *state = to_state(sd);
Mats Randgaard4a31a932013-12-10 09:45:00 -0300769
Pablo Antonb44b2e02015-02-03 14:13:18 -0300770 return state->selected_input == ADV76XX_PAD_HDMI_PORT_A ||
Laurent Pinchartc784b1e2014-01-29 10:08:58 -0300771 state->selected_input == ADV7604_PAD_HDMI_PORT_B ||
772 state->selected_input == ADV7604_PAD_HDMI_PORT_C ||
773 state->selected_input == ADV7604_PAD_HDMI_PORT_D;
Mats Randgaard4a31a932013-12-10 09:45:00 -0300774}
775
Jean-Michel Hautboisbd3e275f2016-01-27 09:04:50 -0200776static const struct v4l2_dv_timings_cap adv7604_timings_cap_analog = {
777 .type = V4L2_DV_BT_656_1120,
778 /* keep this initialization for compatibility with GCC < 4.4.6 */
779 .reserved = { 0 },
780 V4L2_INIT_BT_TIMINGS(0, 1920, 0, 1200, 25000000, 170000000,
781 V4L2_DV_BT_STD_CEA861 | V4L2_DV_BT_STD_DMT |
782 V4L2_DV_BT_STD_GTF | V4L2_DV_BT_STD_CVT,
783 V4L2_DV_BT_CAP_PROGRESSIVE | V4L2_DV_BT_CAP_REDUCED_BLANKING |
784 V4L2_DV_BT_CAP_CUSTOM)
785};
786
787static const struct v4l2_dv_timings_cap adv76xx_timings_cap_digital = {
788 .type = V4L2_DV_BT_656_1120,
789 /* keep this initialization for compatibility with GCC < 4.4.6 */
790 .reserved = { 0 },
791 V4L2_INIT_BT_TIMINGS(0, 1920, 0, 1200, 25000000, 225000000,
792 V4L2_DV_BT_STD_CEA861 | V4L2_DV_BT_STD_DMT |
793 V4L2_DV_BT_STD_GTF | V4L2_DV_BT_STD_CVT,
794 V4L2_DV_BT_CAP_PROGRESSIVE | V4L2_DV_BT_CAP_REDUCED_BLANKING |
795 V4L2_DV_BT_CAP_CUSTOM)
796};
797
Laurent Pinchart9c41e692016-05-24 08:53:39 -0300798/*
799 * Return the DV timings capabilities for the requested sink pad. As a special
800 * case, pad value -1 returns the capabilities for the currently selected input.
801 */
802static const struct v4l2_dv_timings_cap *
803adv76xx_get_dv_timings_cap(struct v4l2_subdev *sd, int pad)
Jean-Michel Hautboisbd3e275f2016-01-27 09:04:50 -0200804{
Laurent Pinchart9c41e692016-05-24 08:53:39 -0300805 if (pad == -1) {
806 struct adv76xx_state *state = to_state(sd);
807
808 pad = state->selected_input;
809 }
810
811 switch (pad) {
812 case ADV76XX_PAD_HDMI_PORT_A:
813 case ADV7604_PAD_HDMI_PORT_B:
814 case ADV7604_PAD_HDMI_PORT_C:
815 case ADV7604_PAD_HDMI_PORT_D:
816 return &adv76xx_timings_cap_digital;
817
818 case ADV7604_PAD_VGA_RGB:
819 case ADV7604_PAD_VGA_COMP:
820 default:
821 return &adv7604_timings_cap_analog;
822 }
Jean-Michel Hautboisbd3e275f2016-01-27 09:04:50 -0200823}
824
825
Mats Randgaard4a31a932013-12-10 09:45:00 -0300826/* ----------------------------------------------------------------------- */
827
Hans Verkuil54450f52012-07-18 05:45:16 -0300828#ifdef CONFIG_VIDEO_ADV_DEBUG
Pablo Antonb44b2e02015-02-03 14:13:18 -0300829static void adv76xx_inv_register(struct v4l2_subdev *sd)
Hans Verkuil54450f52012-07-18 05:45:16 -0300830{
831 v4l2_info(sd, "0x000-0x0ff: IO Map\n");
832 v4l2_info(sd, "0x100-0x1ff: AVLink Map\n");
833 v4l2_info(sd, "0x200-0x2ff: CEC Map\n");
834 v4l2_info(sd, "0x300-0x3ff: InfoFrame Map\n");
835 v4l2_info(sd, "0x400-0x4ff: ESDP Map\n");
836 v4l2_info(sd, "0x500-0x5ff: DPP Map\n");
837 v4l2_info(sd, "0x600-0x6ff: AFE Map\n");
838 v4l2_info(sd, "0x700-0x7ff: Repeater Map\n");
839 v4l2_info(sd, "0x800-0x8ff: EDID Map\n");
840 v4l2_info(sd, "0x900-0x9ff: HDMI Map\n");
841 v4l2_info(sd, "0xa00-0xaff: Test Map\n");
842 v4l2_info(sd, "0xb00-0xbff: CP Map\n");
843 v4l2_info(sd, "0xc00-0xcff: VDP Map\n");
844}
845
Pablo Antonb44b2e02015-02-03 14:13:18 -0300846static int adv76xx_g_register(struct v4l2_subdev *sd,
Hans Verkuil54450f52012-07-18 05:45:16 -0300847 struct v4l2_dbg_register *reg)
848{
Lars-Peter Clausend42010a2013-11-25 15:45:07 -0300849 int ret;
850
Pablo Antonb44b2e02015-02-03 14:13:18 -0300851 ret = adv76xx_read_reg(sd, reg->reg);
Lars-Peter Clausend42010a2013-11-25 15:45:07 -0300852 if (ret < 0) {
Hans Verkuil54450f52012-07-18 05:45:16 -0300853 v4l2_info(sd, "Register %03llx not supported\n", reg->reg);
Pablo Antonb44b2e02015-02-03 14:13:18 -0300854 adv76xx_inv_register(sd);
Lars-Peter Clausend42010a2013-11-25 15:45:07 -0300855 return ret;
Hans Verkuil54450f52012-07-18 05:45:16 -0300856 }
Lars-Peter Clausend42010a2013-11-25 15:45:07 -0300857
858 reg->size = 1;
859 reg->val = ret;
860
Hans Verkuil54450f52012-07-18 05:45:16 -0300861 return 0;
862}
863
Pablo Antonb44b2e02015-02-03 14:13:18 -0300864static int adv76xx_s_register(struct v4l2_subdev *sd,
Hans Verkuil977ba3b2013-03-24 08:28:46 -0300865 const struct v4l2_dbg_register *reg)
Hans Verkuil54450f52012-07-18 05:45:16 -0300866{
Lars-Peter Clausend42010a2013-11-25 15:45:07 -0300867 int ret;
Hans Verkuil15774612013-12-10 10:02:43 -0300868
Pablo Antonb44b2e02015-02-03 14:13:18 -0300869 ret = adv76xx_write_reg(sd, reg->reg, reg->val);
Lars-Peter Clausend42010a2013-11-25 15:45:07 -0300870 if (ret < 0) {
Hans Verkuil54450f52012-07-18 05:45:16 -0300871 v4l2_info(sd, "Register %03llx not supported\n", reg->reg);
Pablo Antonb44b2e02015-02-03 14:13:18 -0300872 adv76xx_inv_register(sd);
Lars-Peter Clausend42010a2013-11-25 15:45:07 -0300873 return ret;
Hans Verkuil54450f52012-07-18 05:45:16 -0300874 }
Lars-Peter Clausend42010a2013-11-25 15:45:07 -0300875
Hans Verkuil54450f52012-07-18 05:45:16 -0300876 return 0;
877}
878#endif
879
Lars-Peter Clausend42010a2013-11-25 15:45:07 -0300880static unsigned int adv7604_read_cable_det(struct v4l2_subdev *sd)
881{
882 u8 value = io_read(sd, 0x6f);
883
884 return ((value & 0x10) >> 4)
885 | ((value & 0x08) >> 2)
886 | ((value & 0x04) << 0)
887 | ((value & 0x02) << 2);
888}
889
890static unsigned int adv7611_read_cable_det(struct v4l2_subdev *sd)
891{
892 u8 value = io_read(sd, 0x6f);
893
894 return value & 1;
895}
896
William Towle7111cdd2015-07-23 09:21:34 -0300897static unsigned int adv7612_read_cable_det(struct v4l2_subdev *sd)
898{
899 /* Reads CABLE_DET_A_RAW. For input B support, need to
900 * account for bit 7 [MSB] of 0x6a (ie. CABLE_DET_B_RAW)
901 */
902 u8 value = io_read(sd, 0x6f);
903
904 return value & 1;
905}
906
Pablo Antonb44b2e02015-02-03 14:13:18 -0300907static int adv76xx_s_detect_tx_5v_ctrl(struct v4l2_subdev *sd)
Hans Verkuil54450f52012-07-18 05:45:16 -0300908{
Pablo Antonb44b2e02015-02-03 14:13:18 -0300909 struct adv76xx_state *state = to_state(sd);
910 const struct adv76xx_chip_info *info = state->info;
Hans Verkuil41a52372015-09-07 08:12:57 -0300911 u16 cable_det = info->read_cable_det(sd);
Hans Verkuil54450f52012-07-18 05:45:16 -0300912
Hans Verkuil41a52372015-09-07 08:12:57 -0300913 return v4l2_ctrl_s_ctrl(state->detect_tx_5v_ctrl, cable_det);
Hans Verkuil54450f52012-07-18 05:45:16 -0300914}
915
Hans Verkuilccbd5bc2012-10-16 10:02:05 -0300916static int find_and_set_predefined_video_timings(struct v4l2_subdev *sd,
917 u8 prim_mode,
Pablo Antonb44b2e02015-02-03 14:13:18 -0300918 const struct adv76xx_video_standards *predef_vid_timings,
Hans Verkuilccbd5bc2012-10-16 10:02:05 -0300919 const struct v4l2_dv_timings *timings)
Hans Verkuil54450f52012-07-18 05:45:16 -0300920{
Hans Verkuilccbd5bc2012-10-16 10:02:05 -0300921 int i;
922
923 for (i = 0; predef_vid_timings[i].timings.bt.width; i++) {
Hans Verkuilef1ed8f2013-08-15 08:28:47 -0300924 if (!v4l2_match_dv_timings(timings, &predef_vid_timings[i].timings,
Hans Verkuil85f9e062015-11-13 09:46:26 -0200925 is_digital_input(sd) ? 250000 : 1000000, false))
Hans Verkuilccbd5bc2012-10-16 10:02:05 -0300926 continue;
927 io_write(sd, 0x00, predef_vid_timings[i].vid_std); /* video std */
928 io_write(sd, 0x01, (predef_vid_timings[i].v_freq << 4) +
929 prim_mode); /* v_freq and prim mode */
930 return 0;
931 }
932
933 return -1;
934}
935
936static int configure_predefined_video_timings(struct v4l2_subdev *sd,
937 struct v4l2_dv_timings *timings)
938{
Pablo Antonb44b2e02015-02-03 14:13:18 -0300939 struct adv76xx_state *state = to_state(sd);
Hans Verkuilccbd5bc2012-10-16 10:02:05 -0300940 int err;
941
942 v4l2_dbg(1, debug, sd, "%s", __func__);
943
Pablo Antonb44b2e02015-02-03 14:13:18 -0300944 if (adv76xx_has_afe(state)) {
Lars-Peter Clausend42010a2013-11-25 15:45:07 -0300945 /* reset to default values */
946 io_write(sd, 0x16, 0x43);
947 io_write(sd, 0x17, 0x5a);
948 }
Hans Verkuilccbd5bc2012-10-16 10:02:05 -0300949 /* disable embedded syncs for auto graphics mode */
Laurent Pinchart22d97e52014-01-30 17:17:42 -0300950 cp_write_clr_set(sd, 0x81, 0x10, 0x00);
Hans Verkuilccbd5bc2012-10-16 10:02:05 -0300951 cp_write(sd, 0x8f, 0x00);
952 cp_write(sd, 0x90, 0x00);
953 cp_write(sd, 0xa2, 0x00);
954 cp_write(sd, 0xa3, 0x00);
955 cp_write(sd, 0xa4, 0x00);
956 cp_write(sd, 0xa5, 0x00);
957 cp_write(sd, 0xa6, 0x00);
958 cp_write(sd, 0xa7, 0x00);
959 cp_write(sd, 0xab, 0x00);
960 cp_write(sd, 0xac, 0x00);
961
Mats Randgaard4a31a932013-12-10 09:45:00 -0300962 if (is_analog_input(sd)) {
Hans Verkuilccbd5bc2012-10-16 10:02:05 -0300963 err = find_and_set_predefined_video_timings(sd,
964 0x01, adv7604_prim_mode_comp, timings);
965 if (err)
966 err = find_and_set_predefined_video_timings(sd,
967 0x02, adv7604_prim_mode_gr, timings);
Mats Randgaard4a31a932013-12-10 09:45:00 -0300968 } else if (is_digital_input(sd)) {
Hans Verkuilccbd5bc2012-10-16 10:02:05 -0300969 err = find_and_set_predefined_video_timings(sd,
Pablo Antonb44b2e02015-02-03 14:13:18 -0300970 0x05, adv76xx_prim_mode_hdmi_comp, timings);
Hans Verkuilccbd5bc2012-10-16 10:02:05 -0300971 if (err)
972 err = find_and_set_predefined_video_timings(sd,
Pablo Antonb44b2e02015-02-03 14:13:18 -0300973 0x06, adv76xx_prim_mode_hdmi_gr, timings);
Mats Randgaard4a31a932013-12-10 09:45:00 -0300974 } else {
975 v4l2_dbg(2, debug, sd, "%s: Unknown port %d selected\n",
976 __func__, state->selected_input);
Hans Verkuilccbd5bc2012-10-16 10:02:05 -0300977 err = -1;
Hans Verkuilccbd5bc2012-10-16 10:02:05 -0300978 }
979
980
981 return err;
982}
983
984static void configure_custom_video_timings(struct v4l2_subdev *sd,
985 const struct v4l2_bt_timings *bt)
986{
Pablo Antonb44b2e02015-02-03 14:13:18 -0300987 struct adv76xx_state *state = to_state(sd);
Hans Verkuilccbd5bc2012-10-16 10:02:05 -0300988 u32 width = htotal(bt);
989 u32 height = vtotal(bt);
990 u16 cp_start_sav = bt->hsync + bt->hbackporch - 4;
991 u16 cp_start_eav = width - bt->hfrontporch;
992 u16 cp_start_vbi = height - bt->vfrontporch;
993 u16 cp_end_vbi = bt->vsync + bt->vbackporch;
994 u16 ch1_fr_ll = (((u32)bt->pixelclock / 100) > 0) ?
Pablo Antonb44b2e02015-02-03 14:13:18 -0300995 ((width * (ADV76XX_FSC / 100)) / ((u32)bt->pixelclock / 100)) : 0;
Hans Verkuilccbd5bc2012-10-16 10:02:05 -0300996 const u8 pll[2] = {
997 0xc0 | ((width >> 8) & 0x1f),
998 width & 0xff
999 };
Hans Verkuil54450f52012-07-18 05:45:16 -03001000
1001 v4l2_dbg(2, debug, sd, "%s\n", __func__);
1002
Mats Randgaard4a31a932013-12-10 09:45:00 -03001003 if (is_analog_input(sd)) {
Hans Verkuilccbd5bc2012-10-16 10:02:05 -03001004 /* auto graphics */
1005 io_write(sd, 0x00, 0x07); /* video std */
1006 io_write(sd, 0x01, 0x02); /* prim mode */
1007 /* enable embedded syncs for auto graphics mode */
Laurent Pinchart22d97e52014-01-30 17:17:42 -03001008 cp_write_clr_set(sd, 0x81, 0x10, 0x10);
Hans Verkuil54450f52012-07-18 05:45:16 -03001009
Hans Verkuilccbd5bc2012-10-16 10:02:05 -03001010 /* Should only be set in auto-graphics mode [REF_02, p. 91-92] */
Hans Verkuil54450f52012-07-18 05:45:16 -03001011 /* setup PLL_DIV_MAN_EN and PLL_DIV_RATIO */
1012 /* IO-map reg. 0x16 and 0x17 should be written in sequence */
Pablo Antonf862f572015-06-19 10:23:06 -03001013 if (regmap_raw_write(state->regmap[ADV76XX_PAGE_IO],
1014 0x16, pll, 2))
Hans Verkuil54450f52012-07-18 05:45:16 -03001015 v4l2_err(sd, "writing to reg 0x16 and 0x17 failed\n");
Hans Verkuil54450f52012-07-18 05:45:16 -03001016
1017 /* active video - horizontal timing */
Hans Verkuil54450f52012-07-18 05:45:16 -03001018 cp_write(sd, 0xa2, (cp_start_sav >> 4) & 0xff);
Hans Verkuilccbd5bc2012-10-16 10:02:05 -03001019 cp_write(sd, 0xa3, ((cp_start_sav & 0x0f) << 4) |
Mats Randgaard4a31a932013-12-10 09:45:00 -03001020 ((cp_start_eav >> 8) & 0x0f));
Hans Verkuil54450f52012-07-18 05:45:16 -03001021 cp_write(sd, 0xa4, cp_start_eav & 0xff);
1022
1023 /* active video - vertical timing */
Hans Verkuil54450f52012-07-18 05:45:16 -03001024 cp_write(sd, 0xa5, (cp_start_vbi >> 4) & 0xff);
Hans Verkuilccbd5bc2012-10-16 10:02:05 -03001025 cp_write(sd, 0xa6, ((cp_start_vbi & 0xf) << 4) |
Mats Randgaard4a31a932013-12-10 09:45:00 -03001026 ((cp_end_vbi >> 8) & 0xf));
Hans Verkuil54450f52012-07-18 05:45:16 -03001027 cp_write(sd, 0xa7, cp_end_vbi & 0xff);
Mats Randgaard4a31a932013-12-10 09:45:00 -03001028 } else if (is_digital_input(sd)) {
Hans Verkuilccbd5bc2012-10-16 10:02:05 -03001029 /* set default prim_mode/vid_std for HDMI
Jonathan McCrohan39c1cb22013-10-20 21:34:01 -03001030 according to [REF_03, c. 4.2] */
Hans Verkuilccbd5bc2012-10-16 10:02:05 -03001031 io_write(sd, 0x00, 0x02); /* video std */
1032 io_write(sd, 0x01, 0x06); /* prim mode */
Mats Randgaard4a31a932013-12-10 09:45:00 -03001033 } else {
1034 v4l2_dbg(2, debug, sd, "%s: Unknown port %d selected\n",
1035 __func__, state->selected_input);
Hans Verkuil54450f52012-07-18 05:45:16 -03001036 }
Hans Verkuil54450f52012-07-18 05:45:16 -03001037
Hans Verkuilccbd5bc2012-10-16 10:02:05 -03001038 cp_write(sd, 0x8f, (ch1_fr_ll >> 8) & 0x7);
1039 cp_write(sd, 0x90, ch1_fr_ll & 0xff);
1040 cp_write(sd, 0xab, (height >> 4) & 0xff);
1041 cp_write(sd, 0xac, (height & 0x0f) << 4);
1042}
Hans Verkuil54450f52012-07-18 05:45:16 -03001043
Pablo Antonb44b2e02015-02-03 14:13:18 -03001044static void adv76xx_set_offset(struct v4l2_subdev *sd, bool auto_offset, u16 offset_a, u16 offset_b, u16 offset_c)
Mats Randgaard5c6c6342013-12-05 10:39:04 -03001045{
Pablo Antonb44b2e02015-02-03 14:13:18 -03001046 struct adv76xx_state *state = to_state(sd);
Mats Randgaard5c6c6342013-12-05 10:39:04 -03001047 u8 offset_buf[4];
1048
1049 if (auto_offset) {
1050 offset_a = 0x3ff;
1051 offset_b = 0x3ff;
1052 offset_c = 0x3ff;
1053 }
1054
1055 v4l2_dbg(2, debug, sd, "%s: %s offset: a = 0x%x, b = 0x%x, c = 0x%x\n",
1056 __func__, auto_offset ? "Auto" : "Manual",
1057 offset_a, offset_b, offset_c);
1058
1059 offset_buf[0] = (cp_read(sd, 0x77) & 0xc0) | ((offset_a & 0x3f0) >> 4);
1060 offset_buf[1] = ((offset_a & 0x00f) << 4) | ((offset_b & 0x3c0) >> 6);
1061 offset_buf[2] = ((offset_b & 0x03f) << 2) | ((offset_c & 0x300) >> 8);
1062 offset_buf[3] = offset_c & 0x0ff;
1063
1064 /* Registers must be written in this order with no i2c access in between */
Pablo Antonf862f572015-06-19 10:23:06 -03001065 if (regmap_raw_write(state->regmap[ADV76XX_PAGE_CP],
1066 0x77, offset_buf, 4))
Mats Randgaard5c6c6342013-12-05 10:39:04 -03001067 v4l2_err(sd, "%s: i2c error writing to CP reg 0x77, 0x78, 0x79, 0x7a\n", __func__);
1068}
1069
Pablo Antonb44b2e02015-02-03 14:13:18 -03001070static void adv76xx_set_gain(struct v4l2_subdev *sd, bool auto_gain, u16 gain_a, u16 gain_b, u16 gain_c)
Mats Randgaard5c6c6342013-12-05 10:39:04 -03001071{
Pablo Antonb44b2e02015-02-03 14:13:18 -03001072 struct adv76xx_state *state = to_state(sd);
Mats Randgaard5c6c6342013-12-05 10:39:04 -03001073 u8 gain_buf[4];
1074 u8 gain_man = 1;
1075 u8 agc_mode_man = 1;
1076
1077 if (auto_gain) {
1078 gain_man = 0;
1079 agc_mode_man = 0;
1080 gain_a = 0x100;
1081 gain_b = 0x100;
1082 gain_c = 0x100;
1083 }
1084
1085 v4l2_dbg(2, debug, sd, "%s: %s gain: a = 0x%x, b = 0x%x, c = 0x%x\n",
1086 __func__, auto_gain ? "Auto" : "Manual",
1087 gain_a, gain_b, gain_c);
1088
1089 gain_buf[0] = ((gain_man << 7) | (agc_mode_man << 6) | ((gain_a & 0x3f0) >> 4));
1090 gain_buf[1] = (((gain_a & 0x00f) << 4) | ((gain_b & 0x3c0) >> 6));
1091 gain_buf[2] = (((gain_b & 0x03f) << 2) | ((gain_c & 0x300) >> 8));
1092 gain_buf[3] = ((gain_c & 0x0ff));
1093
1094 /* Registers must be written in this order with no i2c access in between */
Pablo Antonf862f572015-06-19 10:23:06 -03001095 if (regmap_raw_write(state->regmap[ADV76XX_PAGE_CP],
1096 0x73, gain_buf, 4))
Mats Randgaard5c6c6342013-12-05 10:39:04 -03001097 v4l2_err(sd, "%s: i2c error writing to CP reg 0x73, 0x74, 0x75, 0x76\n", __func__);
1098}
1099
Hans Verkuil54450f52012-07-18 05:45:16 -03001100static void set_rgb_quantization_range(struct v4l2_subdev *sd)
1101{
Pablo Antonb44b2e02015-02-03 14:13:18 -03001102 struct adv76xx_state *state = to_state(sd);
Mats Randgaard5c6c6342013-12-05 10:39:04 -03001103 bool rgb_output = io_read(sd, 0x02) & 0x02;
1104 bool hdmi_signal = hdmi_read(sd, 0x05) & 0x80;
Hans Verkuilfd742462016-06-28 11:43:01 -03001105 u8 y = HDMI_COLORSPACE_RGB;
1106
1107 if (hdmi_signal && (io_read(sd, 0x60) & 1))
1108 y = infoframe_read(sd, 0x01) >> 5;
Hans Verkuil54450f52012-07-18 05:45:16 -03001109
Mats Randgaard5c6c6342013-12-05 10:39:04 -03001110 v4l2_dbg(2, debug, sd, "%s: RGB quantization range: %d, RGB out: %d, HDMI: %d\n",
1111 __func__, state->rgb_quantization_range,
1112 rgb_output, hdmi_signal);
1113
Pablo Antonb44b2e02015-02-03 14:13:18 -03001114 adv76xx_set_gain(sd, true, 0x0, 0x0, 0x0);
1115 adv76xx_set_offset(sd, true, 0x0, 0x0, 0x0);
Hans Verkuilfd742462016-06-28 11:43:01 -03001116 io_write_clr_set(sd, 0x02, 0x04, rgb_output ? 0 : 4);
Mats Randgaard98332392013-12-05 10:05:58 -03001117
Hans Verkuil54450f52012-07-18 05:45:16 -03001118 switch (state->rgb_quantization_range) {
1119 case V4L2_DV_RGB_RANGE_AUTO:
Laurent Pinchartc784b1e2014-01-29 10:08:58 -03001120 if (state->selected_input == ADV7604_PAD_VGA_RGB) {
Mats Randgaard98332392013-12-05 10:05:58 -03001121 /* Receiving analog RGB signal
1122 * Set RGB full range (0-255) */
Laurent Pinchart22d97e52014-01-30 17:17:42 -03001123 io_write_clr_set(sd, 0x02, 0xf0, 0x10);
Mats Randgaard98332392013-12-05 10:05:58 -03001124 break;
1125 }
Hans Verkuil54450f52012-07-18 05:45:16 -03001126
Laurent Pinchartc784b1e2014-01-29 10:08:58 -03001127 if (state->selected_input == ADV7604_PAD_VGA_COMP) {
Mats Randgaard98332392013-12-05 10:05:58 -03001128 /* Receiving analog YPbPr signal
1129 * Set automode */
Laurent Pinchart22d97e52014-01-30 17:17:42 -03001130 io_write_clr_set(sd, 0x02, 0xf0, 0xf0);
Mats Randgaard98332392013-12-05 10:05:58 -03001131 break;
1132 }
1133
Mats Randgaard5c6c6342013-12-05 10:39:04 -03001134 if (hdmi_signal) {
Mats Randgaard98332392013-12-05 10:05:58 -03001135 /* Receiving HDMI signal
1136 * Set automode */
Laurent Pinchart22d97e52014-01-30 17:17:42 -03001137 io_write_clr_set(sd, 0x02, 0xf0, 0xf0);
Mats Randgaard98332392013-12-05 10:05:58 -03001138 break;
1139 }
1140
1141 /* Receiving DVI-D signal
1142 * ADV7604 selects RGB limited range regardless of
1143 * input format (CE/IT) in automatic mode */
Hans Verkuil680fee02015-03-20 14:05:05 -03001144 if (state->timings.bt.flags & V4L2_DV_FL_IS_CE_VIDEO) {
Mats Randgaard98332392013-12-05 10:05:58 -03001145 /* RGB limited range (16-235) */
Laurent Pinchart22d97e52014-01-30 17:17:42 -03001146 io_write_clr_set(sd, 0x02, 0xf0, 0x00);
Mats Randgaard98332392013-12-05 10:05:58 -03001147 } else {
1148 /* RGB full range (0-255) */
Laurent Pinchart22d97e52014-01-30 17:17:42 -03001149 io_write_clr_set(sd, 0x02, 0xf0, 0x10);
Mats Randgaard5c6c6342013-12-05 10:39:04 -03001150
1151 if (is_digital_input(sd) && rgb_output) {
Pablo Antonb44b2e02015-02-03 14:13:18 -03001152 adv76xx_set_offset(sd, false, 0x40, 0x40, 0x40);
Mats Randgaard5c6c6342013-12-05 10:39:04 -03001153 } else {
Pablo Antonb44b2e02015-02-03 14:13:18 -03001154 adv76xx_set_gain(sd, false, 0xe0, 0xe0, 0xe0);
1155 adv76xx_set_offset(sd, false, 0x70, 0x70, 0x70);
Mats Randgaard5c6c6342013-12-05 10:39:04 -03001156 }
Hans Verkuil54450f52012-07-18 05:45:16 -03001157 }
1158 break;
1159 case V4L2_DV_RGB_RANGE_LIMITED:
Laurent Pinchartc784b1e2014-01-29 10:08:58 -03001160 if (state->selected_input == ADV7604_PAD_VGA_COMP) {
Mats Randgaardd261e842013-12-05 10:17:15 -03001161 /* YCrCb limited range (16-235) */
Laurent Pinchart22d97e52014-01-30 17:17:42 -03001162 io_write_clr_set(sd, 0x02, 0xf0, 0x20);
Mats Randgaard5c6c6342013-12-05 10:39:04 -03001163 break;
Mats Randgaardd261e842013-12-05 10:17:15 -03001164 }
Mats Randgaard5c6c6342013-12-05 10:39:04 -03001165
Hans Verkuilfd742462016-06-28 11:43:01 -03001166 if (y != HDMI_COLORSPACE_RGB)
1167 break;
1168
Mats Randgaard5c6c6342013-12-05 10:39:04 -03001169 /* RGB limited range (16-235) */
Laurent Pinchart22d97e52014-01-30 17:17:42 -03001170 io_write_clr_set(sd, 0x02, 0xf0, 0x00);
Mats Randgaard5c6c6342013-12-05 10:39:04 -03001171
Hans Verkuil54450f52012-07-18 05:45:16 -03001172 break;
1173 case V4L2_DV_RGB_RANGE_FULL:
Laurent Pinchartc784b1e2014-01-29 10:08:58 -03001174 if (state->selected_input == ADV7604_PAD_VGA_COMP) {
Mats Randgaardd261e842013-12-05 10:17:15 -03001175 /* YCrCb full range (0-255) */
Laurent Pinchart22d97e52014-01-30 17:17:42 -03001176 io_write_clr_set(sd, 0x02, 0xf0, 0x60);
Mats Randgaard5c6c6342013-12-05 10:39:04 -03001177 break;
1178 }
1179
Hans Verkuilfd742462016-06-28 11:43:01 -03001180 if (y != HDMI_COLORSPACE_RGB)
1181 break;
1182
Mats Randgaard5c6c6342013-12-05 10:39:04 -03001183 /* RGB full range (0-255) */
Laurent Pinchart22d97e52014-01-30 17:17:42 -03001184 io_write_clr_set(sd, 0x02, 0xf0, 0x10);
Mats Randgaard5c6c6342013-12-05 10:39:04 -03001185
1186 if (is_analog_input(sd) || hdmi_signal)
1187 break;
1188
1189 /* Adjust gain/offset for DVI-D signals only */
1190 if (rgb_output) {
Pablo Antonb44b2e02015-02-03 14:13:18 -03001191 adv76xx_set_offset(sd, false, 0x40, 0x40, 0x40);
Mats Randgaardd261e842013-12-05 10:17:15 -03001192 } else {
Pablo Antonb44b2e02015-02-03 14:13:18 -03001193 adv76xx_set_gain(sd, false, 0xe0, 0xe0, 0xe0);
1194 adv76xx_set_offset(sd, false, 0x70, 0x70, 0x70);
Mats Randgaardd261e842013-12-05 10:17:15 -03001195 }
Hans Verkuil54450f52012-07-18 05:45:16 -03001196 break;
1197 }
1198}
1199
Pablo Antonb44b2e02015-02-03 14:13:18 -03001200static int adv76xx_s_ctrl(struct v4l2_ctrl *ctrl)
Hans Verkuil54450f52012-07-18 05:45:16 -03001201{
Laurent Pinchartc2698872014-01-30 15:16:03 -03001202 struct v4l2_subdev *sd =
Pablo Antonb44b2e02015-02-03 14:13:18 -03001203 &container_of(ctrl->handler, struct adv76xx_state, hdl)->sd;
Laurent Pinchartc2698872014-01-30 15:16:03 -03001204
Pablo Antonb44b2e02015-02-03 14:13:18 -03001205 struct adv76xx_state *state = to_state(sd);
Hans Verkuil54450f52012-07-18 05:45:16 -03001206
1207 switch (ctrl->id) {
1208 case V4L2_CID_BRIGHTNESS:
1209 cp_write(sd, 0x3c, ctrl->val);
1210 return 0;
1211 case V4L2_CID_CONTRAST:
1212 cp_write(sd, 0x3a, ctrl->val);
1213 return 0;
1214 case V4L2_CID_SATURATION:
1215 cp_write(sd, 0x3b, ctrl->val);
1216 return 0;
1217 case V4L2_CID_HUE:
1218 cp_write(sd, 0x3d, ctrl->val);
1219 return 0;
1220 case V4L2_CID_DV_RX_RGB_RANGE:
1221 state->rgb_quantization_range = ctrl->val;
1222 set_rgb_quantization_range(sd);
1223 return 0;
1224 case V4L2_CID_ADV_RX_ANALOG_SAMPLING_PHASE:
Pablo Antonb44b2e02015-02-03 14:13:18 -03001225 if (!adv76xx_has_afe(state))
Lars-Peter Clausend42010a2013-11-25 15:45:07 -03001226 return -EINVAL;
Hans Verkuil54450f52012-07-18 05:45:16 -03001227 /* Set the analog sampling phase. This is needed to find the
1228 best sampling phase for analog video: an application or
1229 driver has to try a number of phases and analyze the picture
1230 quality before settling on the best performing phase. */
1231 afe_write(sd, 0xc8, ctrl->val);
1232 return 0;
1233 case V4L2_CID_ADV_RX_FREE_RUN_COLOR_MANUAL:
1234 /* Use the default blue color for free running mode,
1235 or supply your own. */
Laurent Pinchart22d97e52014-01-30 17:17:42 -03001236 cp_write_clr_set(sd, 0xbf, 0x04, ctrl->val << 2);
Hans Verkuil54450f52012-07-18 05:45:16 -03001237 return 0;
1238 case V4L2_CID_ADV_RX_FREE_RUN_COLOR:
1239 cp_write(sd, 0xc0, (ctrl->val & 0xff0000) >> 16);
1240 cp_write(sd, 0xc1, (ctrl->val & 0x00ff00) >> 8);
1241 cp_write(sd, 0xc2, (u8)(ctrl->val & 0x0000ff));
1242 return 0;
1243 }
1244 return -EINVAL;
1245}
1246
Hans Verkuil297a4142016-01-27 11:31:41 -02001247static int adv76xx_g_volatile_ctrl(struct v4l2_ctrl *ctrl)
1248{
1249 struct v4l2_subdev *sd =
1250 &container_of(ctrl->handler, struct adv76xx_state, hdl)->sd;
1251
1252 if (ctrl->id == V4L2_CID_DV_RX_IT_CONTENT_TYPE) {
1253 ctrl->val = V4L2_DV_IT_CONTENT_TYPE_NO_ITC;
1254 if ((io_read(sd, 0x60) & 1) && (infoframe_read(sd, 0x03) & 0x80))
1255 ctrl->val = (infoframe_read(sd, 0x05) >> 4) & 3;
1256 return 0;
1257 }
1258 return -EINVAL;
1259}
1260
Hans Verkuil54450f52012-07-18 05:45:16 -03001261/* ----------------------------------------------------------------------- */
1262
1263static inline bool no_power(struct v4l2_subdev *sd)
1264{
1265 /* Entire chip or CP powered off */
1266 return io_read(sd, 0x0c) & 0x24;
1267}
1268
1269static inline bool no_signal_tmds(struct v4l2_subdev *sd)
1270{
Pablo Antonb44b2e02015-02-03 14:13:18 -03001271 struct adv76xx_state *state = to_state(sd);
Mats Randgaard4a31a932013-12-10 09:45:00 -03001272
1273 return !(io_read(sd, 0x6a) & (0x10 >> state->selected_input));
Hans Verkuil54450f52012-07-18 05:45:16 -03001274}
1275
1276static inline bool no_lock_tmds(struct v4l2_subdev *sd)
1277{
Pablo Antonb44b2e02015-02-03 14:13:18 -03001278 struct adv76xx_state *state = to_state(sd);
1279 const struct adv76xx_chip_info *info = state->info;
Lars-Peter Clausend42010a2013-11-25 15:45:07 -03001280
1281 return (io_read(sd, 0x6a) & info->tdms_lock_mask) != info->tdms_lock_mask;
Hans Verkuil54450f52012-07-18 05:45:16 -03001282}
1283
Martin Buggebb88f322013-08-14 08:52:46 -03001284static inline bool is_hdmi(struct v4l2_subdev *sd)
1285{
1286 return hdmi_read(sd, 0x05) & 0x80;
1287}
1288
Hans Verkuil54450f52012-07-18 05:45:16 -03001289static inline bool no_lock_sspd(struct v4l2_subdev *sd)
1290{
Pablo Antonb44b2e02015-02-03 14:13:18 -03001291 struct adv76xx_state *state = to_state(sd);
Lars-Peter Clausend42010a2013-11-25 15:45:07 -03001292
1293 /*
1294 * Chips without a AFE don't expose registers for the SSPD, so just assume
1295 * that we have a lock.
1296 */
Pablo Antonb44b2e02015-02-03 14:13:18 -03001297 if (adv76xx_has_afe(state))
Lars-Peter Clausend42010a2013-11-25 15:45:07 -03001298 return false;
1299
Hans Verkuil54450f52012-07-18 05:45:16 -03001300 /* TODO channel 2 */
1301 return ((cp_read(sd, 0xb5) & 0xd0) != 0xd0);
1302}
1303
1304static inline bool no_lock_stdi(struct v4l2_subdev *sd)
1305{
1306 /* TODO channel 2 */
1307 return !(cp_read(sd, 0xb1) & 0x80);
1308}
1309
1310static inline bool no_signal(struct v4l2_subdev *sd)
1311{
Hans Verkuil54450f52012-07-18 05:45:16 -03001312 bool ret;
1313
1314 ret = no_power(sd);
1315
1316 ret |= no_lock_stdi(sd);
1317 ret |= no_lock_sspd(sd);
1318
Mats Randgaard4a31a932013-12-10 09:45:00 -03001319 if (is_digital_input(sd)) {
Hans Verkuil54450f52012-07-18 05:45:16 -03001320 ret |= no_lock_tmds(sd);
1321 ret |= no_signal_tmds(sd);
1322 }
1323
1324 return ret;
1325}
1326
1327static inline bool no_lock_cp(struct v4l2_subdev *sd)
1328{
Pablo Antonb44b2e02015-02-03 14:13:18 -03001329 struct adv76xx_state *state = to_state(sd);
Lars-Peter Clausend42010a2013-11-25 15:45:07 -03001330
Pablo Antonb44b2e02015-02-03 14:13:18 -03001331 if (!adv76xx_has_afe(state))
Lars-Peter Clausend42010a2013-11-25 15:45:07 -03001332 return false;
1333
Hans Verkuil54450f52012-07-18 05:45:16 -03001334 /* CP has detected a non standard number of lines on the incoming
1335 video compared to what it is configured to receive by s_dv_timings */
1336 return io_read(sd, 0x12) & 0x01;
1337}
1338
jean-michel.hautbois@vodalys.com58514622015-02-06 11:37:58 -03001339static inline bool in_free_run(struct v4l2_subdev *sd)
1340{
1341 return cp_read(sd, 0xff) & 0x10;
1342}
1343
Pablo Antonb44b2e02015-02-03 14:13:18 -03001344static int adv76xx_g_input_status(struct v4l2_subdev *sd, u32 *status)
Hans Verkuil54450f52012-07-18 05:45:16 -03001345{
Hans Verkuil54450f52012-07-18 05:45:16 -03001346 *status = 0;
1347 *status |= no_power(sd) ? V4L2_IN_ST_NO_POWER : 0;
1348 *status |= no_signal(sd) ? V4L2_IN_ST_NO_SIGNAL : 0;
jean-michel.hautbois@vodalys.com58514622015-02-06 11:37:58 -03001349 if (!in_free_run(sd) && no_lock_cp(sd))
1350 *status |= is_digital_input(sd) ?
1351 V4L2_IN_ST_NO_SYNC : V4L2_IN_ST_NO_H_LOCK;
Hans Verkuil54450f52012-07-18 05:45:16 -03001352
1353 v4l2_dbg(1, debug, sd, "%s: status = 0x%x\n", __func__, *status);
1354
1355 return 0;
1356}
1357
1358/* ----------------------------------------------------------------------- */
1359
Hans Verkuil54450f52012-07-18 05:45:16 -03001360struct stdi_readback {
1361 u16 bl, lcf, lcvs;
1362 u8 hs_pol, vs_pol;
1363 bool interlaced;
1364};
1365
1366static int stdi2dv_timings(struct v4l2_subdev *sd,
1367 struct stdi_readback *stdi,
1368 struct v4l2_dv_timings *timings)
1369{
Pablo Antonb44b2e02015-02-03 14:13:18 -03001370 struct adv76xx_state *state = to_state(sd);
1371 u32 hfreq = (ADV76XX_FSC * 8) / stdi->bl;
Hans Verkuil54450f52012-07-18 05:45:16 -03001372 u32 pix_clk;
1373 int i;
1374
Jean-Michel Hautboisbd3e275f2016-01-27 09:04:50 -02001375 for (i = 0; v4l2_dv_timings_presets[i].bt.width; i++) {
1376 const struct v4l2_bt_timings *bt = &v4l2_dv_timings_presets[i].bt;
1377
1378 if (!v4l2_valid_dv_timings(&v4l2_dv_timings_presets[i],
Laurent Pinchart9c41e692016-05-24 08:53:39 -03001379 adv76xx_get_dv_timings_cap(sd, -1),
Jean-Michel Hautboisbd3e275f2016-01-27 09:04:50 -02001380 adv76xx_check_dv_timings, NULL))
Hans Verkuil54450f52012-07-18 05:45:16 -03001381 continue;
Jean-Michel Hautboisbd3e275f2016-01-27 09:04:50 -02001382 if (vtotal(bt) != stdi->lcf + 1)
1383 continue;
1384 if (bt->vsync != stdi->lcvs)
Hans Verkuil54450f52012-07-18 05:45:16 -03001385 continue;
1386
Jean-Michel Hautboisbd3e275f2016-01-27 09:04:50 -02001387 pix_clk = hfreq * htotal(bt);
Hans Verkuil54450f52012-07-18 05:45:16 -03001388
Jean-Michel Hautboisbd3e275f2016-01-27 09:04:50 -02001389 if ((pix_clk < bt->pixelclock + 1000000) &&
1390 (pix_clk > bt->pixelclock - 1000000)) {
1391 *timings = v4l2_dv_timings_presets[i];
Hans Verkuil54450f52012-07-18 05:45:16 -03001392 return 0;
1393 }
1394 }
1395
Prashant Laddha5fea1bb2015-06-10 13:51:42 -03001396 if (v4l2_detect_cvt(stdi->lcf + 1, hfreq, stdi->lcvs, 0,
Hans Verkuil54450f52012-07-18 05:45:16 -03001397 (stdi->hs_pol == '+' ? V4L2_DV_HSYNC_POS_POL : 0) |
1398 (stdi->vs_pol == '+' ? V4L2_DV_VSYNC_POS_POL : 0),
Prashant Laddha061ddda2015-05-22 02:27:34 -03001399 false, timings))
Hans Verkuil54450f52012-07-18 05:45:16 -03001400 return 0;
1401 if (v4l2_detect_gtf(stdi->lcf + 1, hfreq, stdi->lcvs,
1402 (stdi->hs_pol == '+' ? V4L2_DV_HSYNC_POS_POL : 0) |
1403 (stdi->vs_pol == '+' ? V4L2_DV_VSYNC_POS_POL : 0),
Prashant Laddha061ddda2015-05-22 02:27:34 -03001404 false, state->aspect_ratio, timings))
Hans Verkuil54450f52012-07-18 05:45:16 -03001405 return 0;
1406
Hans Verkuilccbd5bc2012-10-16 10:02:05 -03001407 v4l2_dbg(2, debug, sd,
1408 "%s: No format candidate found for lcvs = %d, lcf=%d, bl = %d, %chsync, %cvsync\n",
1409 __func__, stdi->lcvs, stdi->lcf, stdi->bl,
1410 stdi->hs_pol, stdi->vs_pol);
Hans Verkuil54450f52012-07-18 05:45:16 -03001411 return -1;
1412}
1413
Lars-Peter Clausend42010a2013-11-25 15:45:07 -03001414
Hans Verkuil54450f52012-07-18 05:45:16 -03001415static int read_stdi(struct v4l2_subdev *sd, struct stdi_readback *stdi)
1416{
Pablo Antonb44b2e02015-02-03 14:13:18 -03001417 struct adv76xx_state *state = to_state(sd);
1418 const struct adv76xx_chip_info *info = state->info;
Laurent Pinchart4a2ccdd2014-01-08 20:26:55 -03001419 u8 polarity;
1420
Hans Verkuil54450f52012-07-18 05:45:16 -03001421 if (no_lock_stdi(sd) || no_lock_sspd(sd)) {
1422 v4l2_dbg(2, debug, sd, "%s: STDI and/or SSPD not locked\n", __func__);
1423 return -1;
1424 }
1425
1426 /* read STDI */
Laurent Pinchart51182a92014-01-08 19:30:37 -03001427 stdi->bl = cp_read16(sd, 0xb1, 0x3fff);
Lars-Peter Clausend42010a2013-11-25 15:45:07 -03001428 stdi->lcf = cp_read16(sd, info->lcf_reg, 0x7ff);
Hans Verkuil54450f52012-07-18 05:45:16 -03001429 stdi->lcvs = cp_read(sd, 0xb3) >> 3;
1430 stdi->interlaced = io_read(sd, 0x12) & 0x10;
1431
Pablo Antonb44b2e02015-02-03 14:13:18 -03001432 if (adv76xx_has_afe(state)) {
Lars-Peter Clausend42010a2013-11-25 15:45:07 -03001433 /* read SSPD */
1434 polarity = cp_read(sd, 0xb5);
1435 if ((polarity & 0x03) == 0x01) {
1436 stdi->hs_pol = polarity & 0x10
1437 ? (polarity & 0x08 ? '+' : '-') : 'x';
1438 stdi->vs_pol = polarity & 0x40
1439 ? (polarity & 0x20 ? '+' : '-') : 'x';
1440 } else {
1441 stdi->hs_pol = 'x';
1442 stdi->vs_pol = 'x';
1443 }
Hans Verkuil54450f52012-07-18 05:45:16 -03001444 } else {
Lars-Peter Clausend42010a2013-11-25 15:45:07 -03001445 polarity = hdmi_read(sd, 0x05);
1446 stdi->hs_pol = polarity & 0x20 ? '+' : '-';
1447 stdi->vs_pol = polarity & 0x10 ? '+' : '-';
Hans Verkuil54450f52012-07-18 05:45:16 -03001448 }
1449
1450 if (no_lock_stdi(sd) || no_lock_sspd(sd)) {
1451 v4l2_dbg(2, debug, sd,
1452 "%s: signal lost during readout of STDI/SSPD\n", __func__);
1453 return -1;
1454 }
1455
1456 if (stdi->lcf < 239 || stdi->bl < 8 || stdi->bl == 0x3fff) {
1457 v4l2_dbg(2, debug, sd, "%s: invalid signal\n", __func__);
1458 memset(stdi, 0, sizeof(struct stdi_readback));
1459 return -1;
1460 }
1461
1462 v4l2_dbg(2, debug, sd,
1463 "%s: lcf (frame height - 1) = %d, bl = %d, lcvs (vsync) = %d, %chsync, %cvsync, %s\n",
1464 __func__, stdi->lcf, stdi->bl, stdi->lcvs,
1465 stdi->hs_pol, stdi->vs_pol,
1466 stdi->interlaced ? "interlaced" : "progressive");
1467
1468 return 0;
1469}
1470
Pablo Antonb44b2e02015-02-03 14:13:18 -03001471static int adv76xx_enum_dv_timings(struct v4l2_subdev *sd,
Hans Verkuil54450f52012-07-18 05:45:16 -03001472 struct v4l2_enum_dv_timings *timings)
1473{
Pablo Antonb44b2e02015-02-03 14:13:18 -03001474 struct adv76xx_state *state = to_state(sd);
Laurent Pinchartafec5592014-01-29 10:09:41 -03001475
Laurent Pinchartafec5592014-01-29 10:09:41 -03001476 if (timings->pad >= state->source_pad)
1477 return -EINVAL;
1478
Jean-Michel Hautboisbd3e275f2016-01-27 09:04:50 -02001479 return v4l2_enum_dv_timings_cap(timings,
Laurent Pinchart9c41e692016-05-24 08:53:39 -03001480 adv76xx_get_dv_timings_cap(sd, timings->pad),
1481 adv76xx_check_dv_timings, NULL);
Hans Verkuil54450f52012-07-18 05:45:16 -03001482}
1483
Pablo Antonb44b2e02015-02-03 14:13:18 -03001484static int adv76xx_dv_timings_cap(struct v4l2_subdev *sd,
Laurent Pinchart7515e092014-01-31 08:51:18 -03001485 struct v4l2_dv_timings_cap *cap)
Laurent Pinchartafec5592014-01-29 10:09:41 -03001486{
Pablo Antonb44b2e02015-02-03 14:13:18 -03001487 struct adv76xx_state *state = to_state(sd);
Laurent Pinchart9c41e692016-05-24 08:53:39 -03001488 unsigned int pad = cap->pad;
Laurent Pinchart7515e092014-01-31 08:51:18 -03001489
1490 if (cap->pad >= state->source_pad)
1491 return -EINVAL;
1492
Laurent Pinchart9c41e692016-05-24 08:53:39 -03001493 *cap = *adv76xx_get_dv_timings_cap(sd, pad);
1494 cap->pad = pad;
1495
Laurent Pinchartafec5592014-01-29 10:09:41 -03001496 return 0;
1497}
1498
Hans Verkuil54450f52012-07-18 05:45:16 -03001499/* Fill the optional fields .standards and .flags in struct v4l2_dv_timings
Pablo Antonb44b2e02015-02-03 14:13:18 -03001500 if the format is listed in adv76xx_timings[] */
1501static void adv76xx_fill_optional_dv_timings_fields(struct v4l2_subdev *sd,
Hans Verkuil54450f52012-07-18 05:45:16 -03001502 struct v4l2_dv_timings *timings)
1503{
Laurent Pinchart9c41e692016-05-24 08:53:39 -03001504 v4l2_find_dv_timings_cap(timings, adv76xx_get_dv_timings_cap(sd, -1),
1505 is_digital_input(sd) ? 250000 : 1000000,
1506 adv76xx_check_dv_timings, NULL);
Hans Verkuil54450f52012-07-18 05:45:16 -03001507}
1508
Lars-Peter Clausend42010a2013-11-25 15:45:07 -03001509static unsigned int adv7604_read_hdmi_pixelclock(struct v4l2_subdev *sd)
1510{
1511 unsigned int freq;
1512 int a, b;
1513
1514 a = hdmi_read(sd, 0x06);
1515 b = hdmi_read(sd, 0x3b);
1516 if (a < 0 || b < 0)
1517 return 0;
1518 freq = a * 1000000 + ((b & 0x30) >> 4) * 250000;
1519
1520 if (is_hdmi(sd)) {
1521 /* adjust for deep color mode */
1522 unsigned bits_per_channel = ((hdmi_read(sd, 0x0b) & 0x60) >> 4) + 8;
1523
1524 freq = freq * 8 / bits_per_channel;
1525 }
1526
1527 return freq;
1528}
1529
1530static unsigned int adv7611_read_hdmi_pixelclock(struct v4l2_subdev *sd)
1531{
1532 int a, b;
1533
1534 a = hdmi_read(sd, 0x51);
1535 b = hdmi_read(sd, 0x52);
1536 if (a < 0 || b < 0)
1537 return 0;
1538 return ((a << 1) | (b >> 7)) * 1000000 + (b & 0x7f) * 1000000 / 128;
1539}
1540
Pablo Antonb44b2e02015-02-03 14:13:18 -03001541static int adv76xx_query_dv_timings(struct v4l2_subdev *sd,
Hans Verkuil54450f52012-07-18 05:45:16 -03001542 struct v4l2_dv_timings *timings)
1543{
Pablo Antonb44b2e02015-02-03 14:13:18 -03001544 struct adv76xx_state *state = to_state(sd);
1545 const struct adv76xx_chip_info *info = state->info;
Hans Verkuil54450f52012-07-18 05:45:16 -03001546 struct v4l2_bt_timings *bt = &timings->bt;
1547 struct stdi_readback stdi;
1548
1549 if (!timings)
1550 return -EINVAL;
1551
1552 memset(timings, 0, sizeof(struct v4l2_dv_timings));
1553
1554 if (no_signal(sd)) {
Martin Bugge1e0b9152013-12-05 10:34:46 -03001555 state->restart_stdi_once = true;
Hans Verkuil54450f52012-07-18 05:45:16 -03001556 v4l2_dbg(1, debug, sd, "%s: no valid signal\n", __func__);
1557 return -ENOLINK;
1558 }
1559
1560 /* read STDI */
1561 if (read_stdi(sd, &stdi)) {
1562 v4l2_dbg(1, debug, sd, "%s: STDI/SSPD not locked\n", __func__);
1563 return -ENOLINK;
1564 }
1565 bt->interlaced = stdi.interlaced ?
1566 V4L2_DV_INTERLACED : V4L2_DV_PROGRESSIVE;
1567
Mats Randgaard4a31a932013-12-10 09:45:00 -03001568 if (is_digital_input(sd)) {
Hans Verkuil827c1f52016-07-14 11:53:47 -03001569 bool hdmi_signal = hdmi_read(sd, 0x05) & 0x80;
1570 u8 vic = 0;
1571 u32 w, h;
1572
1573 w = hdmi_read16(sd, 0x07, info->linewidth_mask);
1574 h = hdmi_read16(sd, 0x09, info->field0_height_mask);
1575
1576 if (hdmi_signal && (io_read(sd, 0x60) & 1))
1577 vic = infoframe_read(sd, 0x04);
1578
1579 if (vic && v4l2_find_dv_timings_cea861_vic(timings, vic) &&
1580 bt->width == w && bt->height == h)
1581 goto found;
1582
Hans Verkuil54450f52012-07-18 05:45:16 -03001583 timings->type = V4L2_DV_BT_656_1120;
1584
Hans Verkuil827c1f52016-07-14 11:53:47 -03001585 bt->width = w;
1586 bt->height = h;
Lars-Peter Clausend42010a2013-11-25 15:45:07 -03001587 bt->pixelclock = info->read_hdmi_pixelclock(sd);
jean-michel.hautbois@vodalys.com5380baa2015-04-09 05:25:46 -03001588 bt->hfrontporch = hdmi_read16(sd, 0x20, info->hfrontporch_mask);
1589 bt->hsync = hdmi_read16(sd, 0x22, info->hsync_mask);
1590 bt->hbackporch = hdmi_read16(sd, 0x24, info->hbackporch_mask);
1591 bt->vfrontporch = hdmi_read16(sd, 0x2a,
1592 info->field0_vfrontporch_mask) / 2;
1593 bt->vsync = hdmi_read16(sd, 0x2e, info->field0_vsync_mask) / 2;
1594 bt->vbackporch = hdmi_read16(sd, 0x32,
1595 info->field0_vbackporch_mask) / 2;
Hans Verkuil54450f52012-07-18 05:45:16 -03001596 bt->polarities = ((hdmi_read(sd, 0x05) & 0x10) ? V4L2_DV_VSYNC_POS_POL : 0) |
1597 ((hdmi_read(sd, 0x05) & 0x20) ? V4L2_DV_HSYNC_POS_POL : 0);
1598 if (bt->interlaced == V4L2_DV_INTERLACED) {
jean-michel.hautbois@vodalys.com5380baa2015-04-09 05:25:46 -03001599 bt->height += hdmi_read16(sd, 0x0b,
1600 info->field1_height_mask);
1601 bt->il_vfrontporch = hdmi_read16(sd, 0x2c,
1602 info->field1_vfrontporch_mask) / 2;
1603 bt->il_vsync = hdmi_read16(sd, 0x30,
1604 info->field1_vsync_mask) / 2;
1605 bt->il_vbackporch = hdmi_read16(sd, 0x34,
1606 info->field1_vbackporch_mask) / 2;
Hans Verkuil54450f52012-07-18 05:45:16 -03001607 }
Pablo Antonb44b2e02015-02-03 14:13:18 -03001608 adv76xx_fill_optional_dv_timings_fields(sd, timings);
Hans Verkuil54450f52012-07-18 05:45:16 -03001609 } else {
1610 /* find format
Hans Verkuil80939642012-10-16 05:46:21 -03001611 * Since LCVS values are inaccurate [REF_03, p. 275-276],
Hans Verkuil54450f52012-07-18 05:45:16 -03001612 * stdi2dv_timings() is called with lcvs +-1 if the first attempt fails.
1613 */
1614 if (!stdi2dv_timings(sd, &stdi, timings))
1615 goto found;
1616 stdi.lcvs += 1;
1617 v4l2_dbg(1, debug, sd, "%s: lcvs + 1 = %d\n", __func__, stdi.lcvs);
1618 if (!stdi2dv_timings(sd, &stdi, timings))
1619 goto found;
1620 stdi.lcvs -= 2;
1621 v4l2_dbg(1, debug, sd, "%s: lcvs - 1 = %d\n", __func__, stdi.lcvs);
1622 if (stdi2dv_timings(sd, &stdi, timings)) {
Hans Verkuilcf9afb12012-10-16 10:12:55 -03001623 /*
1624 * The STDI block may measure wrong values, especially
1625 * for lcvs and lcf. If the driver can not find any
1626 * valid timing, the STDI block is restarted to measure
1627 * the video timings again. The function will return an
1628 * error, but the restart of STDI will generate a new
1629 * STDI interrupt and the format detection process will
1630 * restart.
1631 */
1632 if (state->restart_stdi_once) {
1633 v4l2_dbg(1, debug, sd, "%s: restart STDI\n", __func__);
1634 /* TODO restart STDI for Sync Channel 2 */
1635 /* enter one-shot mode */
Laurent Pinchart22d97e52014-01-30 17:17:42 -03001636 cp_write_clr_set(sd, 0x86, 0x06, 0x00);
Hans Verkuilcf9afb12012-10-16 10:12:55 -03001637 /* trigger STDI restart */
Laurent Pinchart22d97e52014-01-30 17:17:42 -03001638 cp_write_clr_set(sd, 0x86, 0x06, 0x04);
Hans Verkuilcf9afb12012-10-16 10:12:55 -03001639 /* reset to continuous mode */
Laurent Pinchart22d97e52014-01-30 17:17:42 -03001640 cp_write_clr_set(sd, 0x86, 0x06, 0x02);
Hans Verkuilcf9afb12012-10-16 10:12:55 -03001641 state->restart_stdi_once = false;
1642 return -ENOLINK;
1643 }
Hans Verkuil54450f52012-07-18 05:45:16 -03001644 v4l2_dbg(1, debug, sd, "%s: format not supported\n", __func__);
1645 return -ERANGE;
1646 }
Hans Verkuilcf9afb12012-10-16 10:12:55 -03001647 state->restart_stdi_once = true;
Hans Verkuil54450f52012-07-18 05:45:16 -03001648 }
1649found:
1650
1651 if (no_signal(sd)) {
1652 v4l2_dbg(1, debug, sd, "%s: signal lost during readout\n", __func__);
1653 memset(timings, 0, sizeof(struct v4l2_dv_timings));
1654 return -ENOLINK;
1655 }
1656
Mats Randgaard4a31a932013-12-10 09:45:00 -03001657 if ((is_analog_input(sd) && bt->pixelclock > 170000000) ||
1658 (is_digital_input(sd) && bt->pixelclock > 225000000)) {
Hans Verkuil54450f52012-07-18 05:45:16 -03001659 v4l2_dbg(1, debug, sd, "%s: pixelclock out of range %d\n",
1660 __func__, (u32)bt->pixelclock);
1661 return -ERANGE;
1662 }
1663
1664 if (debug > 1)
Pablo Antonb44b2e02015-02-03 14:13:18 -03001665 v4l2_print_dv_timings(sd->name, "adv76xx_query_dv_timings: ",
Hans Verkuil11d034c2013-08-15 08:05:59 -03001666 timings, true);
Hans Verkuil54450f52012-07-18 05:45:16 -03001667
1668 return 0;
1669}
1670
Pablo Antonb44b2e02015-02-03 14:13:18 -03001671static int adv76xx_s_dv_timings(struct v4l2_subdev *sd,
Hans Verkuil54450f52012-07-18 05:45:16 -03001672 struct v4l2_dv_timings *timings)
1673{
Pablo Antonb44b2e02015-02-03 14:13:18 -03001674 struct adv76xx_state *state = to_state(sd);
Hans Verkuil54450f52012-07-18 05:45:16 -03001675 struct v4l2_bt_timings *bt;
Hans Verkuilccbd5bc2012-10-16 10:02:05 -03001676 int err;
Hans Verkuil54450f52012-07-18 05:45:16 -03001677
1678 if (!timings)
1679 return -EINVAL;
1680
Hans Verkuil85f9e062015-11-13 09:46:26 -02001681 if (v4l2_match_dv_timings(&state->timings, timings, 0, false)) {
Mats Randgaardd48eb482013-12-12 10:13:35 -03001682 v4l2_dbg(1, debug, sd, "%s: no change\n", __func__);
1683 return 0;
1684 }
1685
Hans Verkuil54450f52012-07-18 05:45:16 -03001686 bt = &timings->bt;
1687
Laurent Pinchart9c41e692016-05-24 08:53:39 -03001688 if (!v4l2_valid_dv_timings(timings, adv76xx_get_dv_timings_cap(sd, -1),
Jean-Michel Hautboisbd3e275f2016-01-27 09:04:50 -02001689 adv76xx_check_dv_timings, NULL))
Hans Verkuil54450f52012-07-18 05:45:16 -03001690 return -ERANGE;
Hans Verkuilccbd5bc2012-10-16 10:02:05 -03001691
Pablo Antonb44b2e02015-02-03 14:13:18 -03001692 adv76xx_fill_optional_dv_timings_fields(sd, timings);
Hans Verkuil54450f52012-07-18 05:45:16 -03001693
1694 state->timings = *timings;
1695
Laurent Pinchart22d97e52014-01-30 17:17:42 -03001696 cp_write_clr_set(sd, 0x91, 0x40, bt->interlaced ? 0x40 : 0x00);
Hans Verkuilccbd5bc2012-10-16 10:02:05 -03001697
1698 /* Use prim_mode and vid_std when available */
1699 err = configure_predefined_video_timings(sd, timings);
1700 if (err) {
1701 /* custom settings when the video format
1702 does not have prim_mode/vid_std */
1703 configure_custom_video_timings(sd, bt);
1704 }
Hans Verkuil54450f52012-07-18 05:45:16 -03001705
1706 set_rgb_quantization_range(sd);
1707
Hans Verkuil54450f52012-07-18 05:45:16 -03001708 if (debug > 1)
Pablo Antonb44b2e02015-02-03 14:13:18 -03001709 v4l2_print_dv_timings(sd->name, "adv76xx_s_dv_timings: ",
Hans Verkuil11d034c2013-08-15 08:05:59 -03001710 timings, true);
Hans Verkuil54450f52012-07-18 05:45:16 -03001711 return 0;
1712}
1713
Pablo Antonb44b2e02015-02-03 14:13:18 -03001714static int adv76xx_g_dv_timings(struct v4l2_subdev *sd,
Hans Verkuil54450f52012-07-18 05:45:16 -03001715 struct v4l2_dv_timings *timings)
1716{
Pablo Antonb44b2e02015-02-03 14:13:18 -03001717 struct adv76xx_state *state = to_state(sd);
Hans Verkuil54450f52012-07-18 05:45:16 -03001718
1719 *timings = state->timings;
1720 return 0;
1721}
1722
Lars-Peter Clausend42010a2013-11-25 15:45:07 -03001723static void adv7604_set_termination(struct v4l2_subdev *sd, bool enable)
1724{
1725 hdmi_write(sd, 0x01, enable ? 0x00 : 0x78);
1726}
1727
1728static void adv7611_set_termination(struct v4l2_subdev *sd, bool enable)
1729{
1730 hdmi_write(sd, 0x83, enable ? 0xfe : 0xff);
1731}
1732
Hans Verkuil6b0d5d32012-10-16 06:40:45 -03001733static void enable_input(struct v4l2_subdev *sd)
Hans Verkuil54450f52012-07-18 05:45:16 -03001734{
Pablo Antonb44b2e02015-02-03 14:13:18 -03001735 struct adv76xx_state *state = to_state(sd);
Hans Verkuil6b0d5d32012-10-16 06:40:45 -03001736
Mats Randgaard4a31a932013-12-10 09:45:00 -03001737 if (is_analog_input(sd)) {
Hans Verkuil54450f52012-07-18 05:45:16 -03001738 io_write(sd, 0x15, 0xb0); /* Disable Tristate of Pins (no audio) */
Mats Randgaard4a31a932013-12-10 09:45:00 -03001739 } else if (is_digital_input(sd)) {
Laurent Pinchart22d97e52014-01-30 17:17:42 -03001740 hdmi_write_clr_set(sd, 0x00, 0x03, state->selected_input);
Lars-Peter Clausend42010a2013-11-25 15:45:07 -03001741 state->info->set_termination(sd, true);
Hans Verkuil54450f52012-07-18 05:45:16 -03001742 io_write(sd, 0x15, 0xa0); /* Disable Tristate of Pins */
Laurent Pinchart22d97e52014-01-30 17:17:42 -03001743 hdmi_write_clr_set(sd, 0x1a, 0x10, 0x00); /* Unmute audio */
Mats Randgaard4a31a932013-12-10 09:45:00 -03001744 } else {
1745 v4l2_dbg(2, debug, sd, "%s: Unknown port %d selected\n",
1746 __func__, state->selected_input);
Hans Verkuil54450f52012-07-18 05:45:16 -03001747 }
1748}
1749
1750static void disable_input(struct v4l2_subdev *sd)
1751{
Pablo Antonb44b2e02015-02-03 14:13:18 -03001752 struct adv76xx_state *state = to_state(sd);
Lars-Peter Clausend42010a2013-11-25 15:45:07 -03001753
Laurent Pinchart22d97e52014-01-30 17:17:42 -03001754 hdmi_write_clr_set(sd, 0x1a, 0x10, 0x10); /* Mute audio */
Mats Randgaard5474b982013-12-05 10:33:41 -03001755 msleep(16); /* 512 samples with >= 32 kHz sample rate [REF_03, c. 7.16.10] */
Hans Verkuil54450f52012-07-18 05:45:16 -03001756 io_write(sd, 0x15, 0xbe); /* Tristate all outputs from video core */
Lars-Peter Clausend42010a2013-11-25 15:45:07 -03001757 state->info->set_termination(sd, false);
Hans Verkuil54450f52012-07-18 05:45:16 -03001758}
1759
Hans Verkuil6b0d5d32012-10-16 06:40:45 -03001760static void select_input(struct v4l2_subdev *sd)
Hans Verkuil54450f52012-07-18 05:45:16 -03001761{
Pablo Antonb44b2e02015-02-03 14:13:18 -03001762 struct adv76xx_state *state = to_state(sd);
1763 const struct adv76xx_chip_info *info = state->info;
Hans Verkuil54450f52012-07-18 05:45:16 -03001764
Mats Randgaard4a31a932013-12-10 09:45:00 -03001765 if (is_analog_input(sd)) {
Pablo Antonb44b2e02015-02-03 14:13:18 -03001766 adv76xx_write_reg_seq(sd, info->recommended_settings[0]);
Hans Verkuil54450f52012-07-18 05:45:16 -03001767
1768 afe_write(sd, 0x00, 0x08); /* power up ADC */
1769 afe_write(sd, 0x01, 0x06); /* power up Analog Front End */
1770 afe_write(sd, 0xc8, 0x00); /* phase control */
Mats Randgaard4a31a932013-12-10 09:45:00 -03001771 } else if (is_digital_input(sd)) {
1772 hdmi_write(sd, 0x00, state->selected_input & 0x03);
Hans Verkuil54450f52012-07-18 05:45:16 -03001773
Pablo Antonb44b2e02015-02-03 14:13:18 -03001774 adv76xx_write_reg_seq(sd, info->recommended_settings[1]);
Hans Verkuil54450f52012-07-18 05:45:16 -03001775
Pablo Antonb44b2e02015-02-03 14:13:18 -03001776 if (adv76xx_has_afe(state)) {
Lars-Peter Clausend42010a2013-11-25 15:45:07 -03001777 afe_write(sd, 0x00, 0xff); /* power down ADC */
1778 afe_write(sd, 0x01, 0xfe); /* power down Analog Front End */
1779 afe_write(sd, 0xc8, 0x40); /* phase control */
1780 }
Hans Verkuil54450f52012-07-18 05:45:16 -03001781
Hans Verkuil54450f52012-07-18 05:45:16 -03001782 cp_write(sd, 0x3e, 0x00); /* CP core pre-gain control */
1783 cp_write(sd, 0xc3, 0x39); /* CP coast control. Graphics mode */
1784 cp_write(sd, 0x40, 0x80); /* CP core pre-gain control. Graphics mode */
Mats Randgaard4a31a932013-12-10 09:45:00 -03001785 } else {
1786 v4l2_dbg(2, debug, sd, "%s: Unknown port %d selected\n",
1787 __func__, state->selected_input);
Hans Verkuil54450f52012-07-18 05:45:16 -03001788 }
1789}
1790
Pablo Antonb44b2e02015-02-03 14:13:18 -03001791static int adv76xx_s_routing(struct v4l2_subdev *sd,
Hans Verkuil54450f52012-07-18 05:45:16 -03001792 u32 input, u32 output, u32 config)
1793{
Pablo Antonb44b2e02015-02-03 14:13:18 -03001794 struct adv76xx_state *state = to_state(sd);
Hans Verkuil54450f52012-07-18 05:45:16 -03001795
Mats Randgaardff4f80f2013-12-05 10:24:05 -03001796 v4l2_dbg(2, debug, sd, "%s: input %d, selected input %d",
1797 __func__, input, state->selected_input);
1798
1799 if (input == state->selected_input)
1800 return 0;
Hans Verkuil54450f52012-07-18 05:45:16 -03001801
Lars-Peter Clausend42010a2013-11-25 15:45:07 -03001802 if (input > state->info->max_port)
1803 return -EINVAL;
1804
Mats Randgaard4a31a932013-12-10 09:45:00 -03001805 state->selected_input = input;
Hans Verkuil54450f52012-07-18 05:45:16 -03001806
1807 disable_input(sd);
Hans Verkuil6b0d5d32012-10-16 06:40:45 -03001808 select_input(sd);
Hans Verkuil6b0d5d32012-10-16 06:40:45 -03001809 enable_input(sd);
Hans Verkuil54450f52012-07-18 05:45:16 -03001810
Lars-Peter Clausen6f5bcfc2015-06-24 13:50:30 -03001811 v4l2_subdev_notify_event(sd, &adv76xx_ev_fmt);
1812
Hans Verkuil54450f52012-07-18 05:45:16 -03001813 return 0;
1814}
1815
Pablo Antonb44b2e02015-02-03 14:13:18 -03001816static int adv76xx_enum_mbus_code(struct v4l2_subdev *sd,
Hans Verkuilf7234132015-03-04 01:47:54 -08001817 struct v4l2_subdev_pad_config *cfg,
Laurent Pinchart539b33b2014-01-26 18:42:37 -03001818 struct v4l2_subdev_mbus_code_enum *code)
Hans Verkuil54450f52012-07-18 05:45:16 -03001819{
Pablo Antonb44b2e02015-02-03 14:13:18 -03001820 struct adv76xx_state *state = to_state(sd);
Hans Verkuil54450f52012-07-18 05:45:16 -03001821
Laurent Pinchart539b33b2014-01-26 18:42:37 -03001822 if (code->index >= state->info->nformats)
1823 return -EINVAL;
1824
1825 code->code = state->info->formats[code->index].code;
1826
1827 return 0;
1828}
1829
Pablo Antonb44b2e02015-02-03 14:13:18 -03001830static void adv76xx_fill_format(struct adv76xx_state *state,
Laurent Pinchart539b33b2014-01-26 18:42:37 -03001831 struct v4l2_mbus_framefmt *format)
1832{
1833 memset(format, 0, sizeof(*format));
1834
1835 format->width = state->timings.bt.width;
1836 format->height = state->timings.bt.height;
1837 format->field = V4L2_FIELD_NONE;
Hans Verkuil680fee02015-03-20 14:05:05 -03001838 format->colorspace = V4L2_COLORSPACE_SRGB;
Laurent Pinchart539b33b2014-01-26 18:42:37 -03001839
Hans Verkuil680fee02015-03-20 14:05:05 -03001840 if (state->timings.bt.flags & V4L2_DV_FL_IS_CE_VIDEO)
Laurent Pinchart539b33b2014-01-26 18:42:37 -03001841 format->colorspace = (state->timings.bt.height <= 576) ?
Hans Verkuil54450f52012-07-18 05:45:16 -03001842 V4L2_COLORSPACE_SMPTE170M : V4L2_COLORSPACE_REC709;
Laurent Pinchart539b33b2014-01-26 18:42:37 -03001843}
1844
1845/*
1846 * Compute the op_ch_sel value required to obtain on the bus the component order
1847 * corresponding to the selected format taking into account bus reordering
1848 * applied by the board at the output of the device.
1849 *
1850 * The following table gives the op_ch_value from the format component order
1851 * (expressed as op_ch_sel value in column) and the bus reordering (expressed as
Pablo Antonb44b2e02015-02-03 14:13:18 -03001852 * adv76xx_bus_order value in row).
Laurent Pinchart539b33b2014-01-26 18:42:37 -03001853 *
1854 * | GBR(0) GRB(1) BGR(2) RGB(3) BRG(4) RBG(5)
1855 * ----------+-------------------------------------------------
1856 * RGB (NOP) | GBR GRB BGR RGB BRG RBG
1857 * GRB (1-2) | BGR RGB GBR GRB RBG BRG
1858 * RBG (2-3) | GRB GBR BRG RBG BGR RGB
1859 * BGR (1-3) | RBG BRG RGB BGR GRB GBR
1860 * BRG (ROR) | BRG RBG GRB GBR RGB BGR
1861 * GBR (ROL) | RGB BGR RBG BRG GBR GRB
1862 */
Pablo Antonb44b2e02015-02-03 14:13:18 -03001863static unsigned int adv76xx_op_ch_sel(struct adv76xx_state *state)
Laurent Pinchart539b33b2014-01-26 18:42:37 -03001864{
1865#define _SEL(a,b,c,d,e,f) { \
Pablo Antonb44b2e02015-02-03 14:13:18 -03001866 ADV76XX_OP_CH_SEL_##a, ADV76XX_OP_CH_SEL_##b, ADV76XX_OP_CH_SEL_##c, \
1867 ADV76XX_OP_CH_SEL_##d, ADV76XX_OP_CH_SEL_##e, ADV76XX_OP_CH_SEL_##f }
Laurent Pinchart539b33b2014-01-26 18:42:37 -03001868#define _BUS(x) [ADV7604_BUS_ORDER_##x]
1869
1870 static const unsigned int op_ch_sel[6][6] = {
1871 _BUS(RGB) /* NOP */ = _SEL(GBR, GRB, BGR, RGB, BRG, RBG),
1872 _BUS(GRB) /* 1-2 */ = _SEL(BGR, RGB, GBR, GRB, RBG, BRG),
1873 _BUS(RBG) /* 2-3 */ = _SEL(GRB, GBR, BRG, RBG, BGR, RGB),
1874 _BUS(BGR) /* 1-3 */ = _SEL(RBG, BRG, RGB, BGR, GRB, GBR),
1875 _BUS(BRG) /* ROR */ = _SEL(BRG, RBG, GRB, GBR, RGB, BGR),
1876 _BUS(GBR) /* ROL */ = _SEL(RGB, BGR, RBG, BRG, GBR, GRB),
1877 };
1878
1879 return op_ch_sel[state->pdata.bus_order][state->format->op_ch_sel >> 5];
1880}
1881
Pablo Antonb44b2e02015-02-03 14:13:18 -03001882static void adv76xx_setup_format(struct adv76xx_state *state)
Laurent Pinchart539b33b2014-01-26 18:42:37 -03001883{
1884 struct v4l2_subdev *sd = &state->sd;
1885
Laurent Pinchart22d97e52014-01-30 17:17:42 -03001886 io_write_clr_set(sd, 0x02, 0x02,
Pablo Antonb44b2e02015-02-03 14:13:18 -03001887 state->format->rgb_out ? ADV76XX_RGB_OUT : 0);
Laurent Pinchart539b33b2014-01-26 18:42:37 -03001888 io_write(sd, 0x03, state->format->op_format_sel |
1889 state->pdata.op_format_mode_sel);
Pablo Antonb44b2e02015-02-03 14:13:18 -03001890 io_write_clr_set(sd, 0x04, 0xe0, adv76xx_op_ch_sel(state));
Laurent Pinchart22d97e52014-01-30 17:17:42 -03001891 io_write_clr_set(sd, 0x05, 0x01,
Pablo Antonb44b2e02015-02-03 14:13:18 -03001892 state->format->swap_cb_cr ? ADV76XX_OP_SWAP_CB_CR : 0);
Hans Verkuilfd742462016-06-28 11:43:01 -03001893 set_rgb_quantization_range(sd);
Laurent Pinchart539b33b2014-01-26 18:42:37 -03001894}
1895
Hans Verkuilf7234132015-03-04 01:47:54 -08001896static int adv76xx_get_format(struct v4l2_subdev *sd,
1897 struct v4l2_subdev_pad_config *cfg,
Laurent Pinchart539b33b2014-01-26 18:42:37 -03001898 struct v4l2_subdev_format *format)
1899{
Pablo Antonb44b2e02015-02-03 14:13:18 -03001900 struct adv76xx_state *state = to_state(sd);
Laurent Pinchart539b33b2014-01-26 18:42:37 -03001901
1902 if (format->pad != state->source_pad)
1903 return -EINVAL;
1904
Pablo Antonb44b2e02015-02-03 14:13:18 -03001905 adv76xx_fill_format(state, &format->format);
Laurent Pinchart539b33b2014-01-26 18:42:37 -03001906
1907 if (format->which == V4L2_SUBDEV_FORMAT_TRY) {
1908 struct v4l2_mbus_framefmt *fmt;
1909
Hans Verkuilf7234132015-03-04 01:47:54 -08001910 fmt = v4l2_subdev_get_try_format(sd, cfg, format->pad);
Laurent Pinchart539b33b2014-01-26 18:42:37 -03001911 format->format.code = fmt->code;
1912 } else {
1913 format->format.code = state->format->code;
Hans Verkuil54450f52012-07-18 05:45:16 -03001914 }
Laurent Pinchart539b33b2014-01-26 18:42:37 -03001915
1916 return 0;
1917}
1918
Ulrich Hechtb7d4d2f2015-12-22 12:22:01 -02001919static int adv76xx_get_selection(struct v4l2_subdev *sd,
1920 struct v4l2_subdev_pad_config *cfg,
1921 struct v4l2_subdev_selection *sel)
1922{
1923 struct adv76xx_state *state = to_state(sd);
1924
1925 if (sel->which != V4L2_SUBDEV_FORMAT_ACTIVE)
1926 return -EINVAL;
1927 /* Only CROP, CROP_DEFAULT and CROP_BOUNDS are supported */
1928 if (sel->target > V4L2_SEL_TGT_CROP_BOUNDS)
1929 return -EINVAL;
1930
1931 sel->r.left = 0;
1932 sel->r.top = 0;
1933 sel->r.width = state->timings.bt.width;
1934 sel->r.height = state->timings.bt.height;
1935
1936 return 0;
1937}
1938
Hans Verkuilf7234132015-03-04 01:47:54 -08001939static int adv76xx_set_format(struct v4l2_subdev *sd,
1940 struct v4l2_subdev_pad_config *cfg,
Laurent Pinchart539b33b2014-01-26 18:42:37 -03001941 struct v4l2_subdev_format *format)
1942{
Pablo Antonb44b2e02015-02-03 14:13:18 -03001943 struct adv76xx_state *state = to_state(sd);
1944 const struct adv76xx_format_info *info;
Laurent Pinchart539b33b2014-01-26 18:42:37 -03001945
1946 if (format->pad != state->source_pad)
1947 return -EINVAL;
1948
Pablo Antonb44b2e02015-02-03 14:13:18 -03001949 info = adv76xx_format_info(state, format->format.code);
Laurent Pinchart539b33b2014-01-26 18:42:37 -03001950 if (info == NULL)
Pablo Antonb44b2e02015-02-03 14:13:18 -03001951 info = adv76xx_format_info(state, MEDIA_BUS_FMT_YUYV8_2X8);
Laurent Pinchart539b33b2014-01-26 18:42:37 -03001952
Pablo Antonb44b2e02015-02-03 14:13:18 -03001953 adv76xx_fill_format(state, &format->format);
Laurent Pinchart539b33b2014-01-26 18:42:37 -03001954 format->format.code = info->code;
1955
1956 if (format->which == V4L2_SUBDEV_FORMAT_TRY) {
1957 struct v4l2_mbus_framefmt *fmt;
1958
Hans Verkuilf7234132015-03-04 01:47:54 -08001959 fmt = v4l2_subdev_get_try_format(sd, cfg, format->pad);
Laurent Pinchart539b33b2014-01-26 18:42:37 -03001960 fmt->code = format->format.code;
1961 } else {
1962 state->format = info;
Pablo Antonb44b2e02015-02-03 14:13:18 -03001963 adv76xx_setup_format(state);
Laurent Pinchart539b33b2014-01-26 18:42:37 -03001964 }
1965
Hans Verkuil54450f52012-07-18 05:45:16 -03001966 return 0;
1967}
1968
Hans Verkuil41a52372015-09-07 08:12:57 -03001969#if IS_ENABLED(CONFIG_VIDEO_ADV7604_CEC)
1970static void adv76xx_cec_tx_raw_status(struct v4l2_subdev *sd, u8 tx_raw_status)
1971{
1972 struct adv76xx_state *state = to_state(sd);
1973
1974 if ((cec_read(sd, 0x11) & 0x01) == 0) {
1975 v4l2_dbg(1, debug, sd, "%s: tx raw: tx disabled\n", __func__);
1976 return;
1977 }
1978
1979 if (tx_raw_status & 0x02) {
1980 v4l2_dbg(1, debug, sd, "%s: tx raw: arbitration lost\n",
1981 __func__);
1982 cec_transmit_done(state->cec_adap, CEC_TX_STATUS_ARB_LOST,
1983 1, 0, 0, 0);
1984 }
1985 if (tx_raw_status & 0x04) {
1986 u8 status;
1987 u8 nack_cnt;
1988 u8 low_drive_cnt;
1989
1990 v4l2_dbg(1, debug, sd, "%s: tx raw: retry failed\n", __func__);
1991 /*
1992 * We set this status bit since this hardware performs
1993 * retransmissions.
1994 */
1995 status = CEC_TX_STATUS_MAX_RETRIES;
1996 nack_cnt = cec_read(sd, 0x14) & 0xf;
1997 if (nack_cnt)
1998 status |= CEC_TX_STATUS_NACK;
1999 low_drive_cnt = cec_read(sd, 0x14) >> 4;
2000 if (low_drive_cnt)
2001 status |= CEC_TX_STATUS_LOW_DRIVE;
2002 cec_transmit_done(state->cec_adap, status,
2003 0, nack_cnt, low_drive_cnt, 0);
2004 return;
2005 }
2006 if (tx_raw_status & 0x01) {
2007 v4l2_dbg(1, debug, sd, "%s: tx raw: ready ok\n", __func__);
2008 cec_transmit_done(state->cec_adap, CEC_TX_STATUS_OK, 0, 0, 0, 0);
2009 return;
2010 }
2011}
2012
2013static void adv76xx_cec_isr(struct v4l2_subdev *sd, bool *handled)
2014{
2015 struct adv76xx_state *state = to_state(sd);
2016 u8 cec_irq;
2017
2018 /* cec controller */
2019 cec_irq = io_read(sd, 0x4d) & 0x0f;
2020 if (!cec_irq)
2021 return;
2022
2023 v4l2_dbg(1, debug, sd, "%s: cec: irq 0x%x\n", __func__, cec_irq);
2024 adv76xx_cec_tx_raw_status(sd, cec_irq);
2025 if (cec_irq & 0x08) {
2026 struct cec_msg msg;
2027
2028 msg.len = cec_read(sd, 0x25) & 0x1f;
2029 if (msg.len > 16)
2030 msg.len = 16;
2031
2032 if (msg.len) {
2033 u8 i;
2034
2035 for (i = 0; i < msg.len; i++)
2036 msg.msg[i] = cec_read(sd, i + 0x15);
2037 cec_write(sd, 0x26, 0x01); /* re-enable rx */
2038 cec_received_msg(state->cec_adap, &msg);
2039 }
2040 }
2041
2042 /* note: the bit order is swapped between 0x4d and 0x4e */
2043 cec_irq = ((cec_irq & 0x08) >> 3) | ((cec_irq & 0x04) >> 1) |
2044 ((cec_irq & 0x02) << 1) | ((cec_irq & 0x01) << 3);
2045 io_write(sd, 0x4e, cec_irq);
2046
2047 if (handled)
2048 *handled = true;
2049}
2050
2051static int adv76xx_cec_adap_enable(struct cec_adapter *adap, bool enable)
2052{
2053 struct adv76xx_state *state = adap->priv;
2054 struct v4l2_subdev *sd = &state->sd;
2055
2056 if (!state->cec_enabled_adap && enable) {
2057 cec_write_clr_set(sd, 0x2a, 0x01, 0x01); /* power up cec */
2058 cec_write(sd, 0x2c, 0x01); /* cec soft reset */
2059 cec_write_clr_set(sd, 0x11, 0x01, 0); /* initially disable tx */
2060 /* enabled irqs: */
2061 /* tx: ready */
2062 /* tx: arbitration lost */
2063 /* tx: retry timeout */
2064 /* rx: ready */
2065 io_write_clr_set(sd, 0x50, 0x0f, 0x0f);
2066 cec_write(sd, 0x26, 0x01); /* enable rx */
2067 } else if (state->cec_enabled_adap && !enable) {
2068 /* disable cec interrupts */
2069 io_write_clr_set(sd, 0x50, 0x0f, 0x00);
2070 /* disable address mask 1-3 */
2071 cec_write_clr_set(sd, 0x27, 0x70, 0x00);
2072 /* power down cec section */
2073 cec_write_clr_set(sd, 0x2a, 0x01, 0x00);
2074 state->cec_valid_addrs = 0;
2075 }
2076 state->cec_enabled_adap = enable;
2077 adv76xx_s_detect_tx_5v_ctrl(sd);
2078 return 0;
2079}
2080
2081static int adv76xx_cec_adap_log_addr(struct cec_adapter *adap, u8 addr)
2082{
2083 struct adv76xx_state *state = adap->priv;
2084 struct v4l2_subdev *sd = &state->sd;
2085 unsigned int i, free_idx = ADV76XX_MAX_ADDRS;
2086
2087 if (!state->cec_enabled_adap)
2088 return addr == CEC_LOG_ADDR_INVALID ? 0 : -EIO;
2089
2090 if (addr == CEC_LOG_ADDR_INVALID) {
2091 cec_write_clr_set(sd, 0x27, 0x70, 0);
2092 state->cec_valid_addrs = 0;
2093 return 0;
2094 }
2095
2096 for (i = 0; i < ADV76XX_MAX_ADDRS; i++) {
2097 bool is_valid = state->cec_valid_addrs & (1 << i);
2098
2099 if (free_idx == ADV76XX_MAX_ADDRS && !is_valid)
2100 free_idx = i;
2101 if (is_valid && state->cec_addr[i] == addr)
2102 return 0;
2103 }
2104 if (i == ADV76XX_MAX_ADDRS) {
2105 i = free_idx;
2106 if (i == ADV76XX_MAX_ADDRS)
2107 return -ENXIO;
2108 }
2109 state->cec_addr[i] = addr;
2110 state->cec_valid_addrs |= 1 << i;
2111
2112 switch (i) {
2113 case 0:
2114 /* enable address mask 0 */
2115 cec_write_clr_set(sd, 0x27, 0x10, 0x10);
2116 /* set address for mask 0 */
2117 cec_write_clr_set(sd, 0x28, 0x0f, addr);
2118 break;
2119 case 1:
2120 /* enable address mask 1 */
2121 cec_write_clr_set(sd, 0x27, 0x20, 0x20);
2122 /* set address for mask 1 */
2123 cec_write_clr_set(sd, 0x28, 0xf0, addr << 4);
2124 break;
2125 case 2:
2126 /* enable address mask 2 */
2127 cec_write_clr_set(sd, 0x27, 0x40, 0x40);
2128 /* set address for mask 1 */
2129 cec_write_clr_set(sd, 0x29, 0x0f, addr);
2130 break;
2131 }
2132 return 0;
2133}
2134
2135static int adv76xx_cec_adap_transmit(struct cec_adapter *adap, u8 attempts,
2136 u32 signal_free_time, struct cec_msg *msg)
2137{
2138 struct adv76xx_state *state = adap->priv;
2139 struct v4l2_subdev *sd = &state->sd;
2140 u8 len = msg->len;
2141 unsigned int i;
2142
2143 /*
2144 * The number of retries is the number of attempts - 1, but retry
2145 * at least once. It's not clear if a value of 0 is allowed, so
2146 * let's do at least one retry.
2147 */
2148 cec_write_clr_set(sd, 0x12, 0x70, max(1, attempts - 1) << 4);
2149
2150 if (len > 16) {
2151 v4l2_err(sd, "%s: len exceeded 16 (%d)\n", __func__, len);
2152 return -EINVAL;
2153 }
2154
2155 /* write data */
2156 for (i = 0; i < len; i++)
2157 cec_write(sd, i, msg->msg[i]);
2158
2159 /* set length (data + header) */
2160 cec_write(sd, 0x10, len);
2161 /* start transmit, enable tx */
2162 cec_write(sd, 0x11, 0x01);
2163 return 0;
2164}
2165
2166static const struct cec_adap_ops adv76xx_cec_adap_ops = {
2167 .adap_enable = adv76xx_cec_adap_enable,
2168 .adap_log_addr = adv76xx_cec_adap_log_addr,
2169 .adap_transmit = adv76xx_cec_adap_transmit,
2170};
2171#endif
2172
Pablo Antonb44b2e02015-02-03 14:13:18 -03002173static int adv76xx_isr(struct v4l2_subdev *sd, u32 status, bool *handled)
Hans Verkuil54450f52012-07-18 05:45:16 -03002174{
Pablo Antonb44b2e02015-02-03 14:13:18 -03002175 struct adv76xx_state *state = to_state(sd);
2176 const struct adv76xx_chip_info *info = state->info;
Mats Randgaardf24d2292013-12-10 10:15:13 -03002177 const u8 irq_reg_0x43 = io_read(sd, 0x43);
2178 const u8 irq_reg_0x6b = io_read(sd, 0x6b);
2179 const u8 irq_reg_0x70 = io_read(sd, 0x70);
2180 u8 fmt_change_digital;
2181 u8 fmt_change;
2182 u8 tx_5v;
2183
2184 if (irq_reg_0x43)
2185 io_write(sd, 0x44, irq_reg_0x43);
2186 if (irq_reg_0x70)
2187 io_write(sd, 0x71, irq_reg_0x70);
2188 if (irq_reg_0x6b)
2189 io_write(sd, 0x6c, irq_reg_0x6b);
Hans Verkuil54450f52012-07-18 05:45:16 -03002190
Mats Randgaardff4f80f2013-12-05 10:24:05 -03002191 v4l2_dbg(2, debug, sd, "%s: ", __func__);
2192
Hans Verkuil54450f52012-07-18 05:45:16 -03002193 /* format change */
Mats Randgaardf24d2292013-12-10 10:15:13 -03002194 fmt_change = irq_reg_0x43 & 0x98;
Lars-Peter Clausend42010a2013-11-25 15:45:07 -03002195 fmt_change_digital = is_digital_input(sd)
2196 ? irq_reg_0x6b & info->fmt_change_digital_mask
2197 : 0;
Mats Randgaard14d03232013-12-05 10:26:11 -03002198
Hans Verkuil54450f52012-07-18 05:45:16 -03002199 if (fmt_change || fmt_change_digital) {
2200 v4l2_dbg(1, debug, sd,
Mats Randgaard25a64ac2013-08-14 07:58:45 -03002201 "%s: fmt_change = 0x%x, fmt_change_digital = 0x%x\n",
Hans Verkuil54450f52012-07-18 05:45:16 -03002202 __func__, fmt_change, fmt_change_digital);
Mats Randgaard25a64ac2013-08-14 07:58:45 -03002203
Lars-Peter Clausen6f5bcfc2015-06-24 13:50:30 -03002204 v4l2_subdev_notify_event(sd, &adv76xx_ev_fmt);
Mats Randgaard25a64ac2013-08-14 07:58:45 -03002205
Hans Verkuil54450f52012-07-18 05:45:16 -03002206 if (handled)
2207 *handled = true;
2208 }
Mats Randgaardf24d2292013-12-10 10:15:13 -03002209 /* HDMI/DVI mode */
2210 if (irq_reg_0x6b & 0x01) {
2211 v4l2_dbg(1, debug, sd, "%s: irq %s mode\n", __func__,
2212 (io_read(sd, 0x6a) & 0x01) ? "HDMI" : "DVI");
2213 set_rgb_quantization_range(sd);
2214 if (handled)
2215 *handled = true;
2216 }
2217
Hans Verkuil41a52372015-09-07 08:12:57 -03002218#if IS_ENABLED(CONFIG_VIDEO_ADV7604_CEC)
2219 /* cec */
2220 adv76xx_cec_isr(sd, handled);
2221#endif
2222
Hans Verkuil54450f52012-07-18 05:45:16 -03002223 /* tx 5v detect */
Hans Verkuil0ba45812016-02-10 08:09:10 -02002224 tx_5v = irq_reg_0x70 & info->cable_det_mask;
Hans Verkuil54450f52012-07-18 05:45:16 -03002225 if (tx_5v) {
2226 v4l2_dbg(1, debug, sd, "%s: tx_5v: 0x%x\n", __func__, tx_5v);
Pablo Antonb44b2e02015-02-03 14:13:18 -03002227 adv76xx_s_detect_tx_5v_ctrl(sd);
Hans Verkuil54450f52012-07-18 05:45:16 -03002228 if (handled)
2229 *handled = true;
2230 }
2231 return 0;
2232}
2233
Pablo Antonb44b2e02015-02-03 14:13:18 -03002234static int adv76xx_get_edid(struct v4l2_subdev *sd, struct v4l2_edid *edid)
Hans Verkuil54450f52012-07-18 05:45:16 -03002235{
Pablo Antonb44b2e02015-02-03 14:13:18 -03002236 struct adv76xx_state *state = to_state(sd);
Mats Randgaard4a31a932013-12-10 09:45:00 -03002237 u8 *data = NULL;
Hans Verkuil54450f52012-07-18 05:45:16 -03002238
Hans Verkuildd9ac112014-11-07 09:34:57 -03002239 memset(edid->reserved, 0, sizeof(edid->reserved));
Mats Randgaard4a31a932013-12-10 09:45:00 -03002240
2241 switch (edid->pad) {
Pablo Antonb44b2e02015-02-03 14:13:18 -03002242 case ADV76XX_PAD_HDMI_PORT_A:
Laurent Pinchartc784b1e2014-01-29 10:08:58 -03002243 case ADV7604_PAD_HDMI_PORT_B:
2244 case ADV7604_PAD_HDMI_PORT_C:
2245 case ADV7604_PAD_HDMI_PORT_D:
Mats Randgaard4a31a932013-12-10 09:45:00 -03002246 if (state->edid.present & (1 << edid->pad))
2247 data = state->edid.edid;
2248 break;
2249 default:
2250 return -EINVAL;
Mats Randgaard4a31a932013-12-10 09:45:00 -03002251 }
Hans Verkuildd9ac112014-11-07 09:34:57 -03002252
2253 if (edid->start_block == 0 && edid->blocks == 0) {
2254 edid->blocks = data ? state->edid.blocks : 0;
2255 return 0;
2256 }
2257
2258 if (data == NULL)
Mats Randgaard4a31a932013-12-10 09:45:00 -03002259 return -ENODATA;
2260
Hans Verkuildd9ac112014-11-07 09:34:57 -03002261 if (edid->start_block >= state->edid.blocks)
2262 return -EINVAL;
2263
2264 if (edid->start_block + edid->blocks > state->edid.blocks)
2265 edid->blocks = state->edid.blocks - edid->start_block;
2266
2267 memcpy(edid->edid, data + edid->start_block * 128, edid->blocks * 128);
2268
Hans Verkuil54450f52012-07-18 05:45:16 -03002269 return 0;
2270}
2271
Pablo Antonb44b2e02015-02-03 14:13:18 -03002272static int adv76xx_set_edid(struct v4l2_subdev *sd, struct v4l2_edid *edid)
Hans Verkuil54450f52012-07-18 05:45:16 -03002273{
Pablo Antonb44b2e02015-02-03 14:13:18 -03002274 struct adv76xx_state *state = to_state(sd);
2275 const struct adv76xx_chip_info *info = state->info;
Hans Verkuil41a52372015-09-07 08:12:57 -03002276 unsigned int spa_loc;
2277 u16 pa;
Hans Verkuil54450f52012-07-18 05:45:16 -03002278 int err;
Mats Randgaarddd08beb2013-12-10 09:57:09 -03002279 int i;
Hans Verkuil54450f52012-07-18 05:45:16 -03002280
Hans Verkuildd9ac112014-11-07 09:34:57 -03002281 memset(edid->reserved, 0, sizeof(edid->reserved));
2282
Laurent Pinchartc784b1e2014-01-29 10:08:58 -03002283 if (edid->pad > ADV7604_PAD_HDMI_PORT_D)
Hans Verkuil54450f52012-07-18 05:45:16 -03002284 return -EINVAL;
2285 if (edid->start_block != 0)
2286 return -EINVAL;
2287 if (edid->blocks == 0) {
Mats Randgaard3e86aa82013-12-10 09:55:18 -03002288 /* Disable hotplug and I2C access to EDID RAM from DDC port */
Mats Randgaard4a31a932013-12-10 09:45:00 -03002289 state->edid.present &= ~(1 << edid->pad);
Pablo Antonb44b2e02015-02-03 14:13:18 -03002290 adv76xx_set_hpd(state, state->edid.present);
Laurent Pinchart22d97e52014-01-30 17:17:42 -03002291 rep_write_clr_set(sd, info->edid_enable_reg, 0x0f, state->edid.present);
Mats Randgaard3e86aa82013-12-10 09:55:18 -03002292
Hans Verkuil54450f52012-07-18 05:45:16 -03002293 /* Fall back to a 16:9 aspect ratio */
2294 state->aspect_ratio.numerator = 16;
2295 state->aspect_ratio.denominator = 9;
Mats Randgaard3e86aa82013-12-10 09:55:18 -03002296
2297 if (!state->edid.present)
2298 state->edid.blocks = 0;
2299
2300 v4l2_dbg(2, debug, sd, "%s: clear EDID pad %d, edid.present = 0x%x\n",
2301 __func__, edid->pad, state->edid.present);
Hans Verkuil54450f52012-07-18 05:45:16 -03002302 return 0;
2303 }
Mats Randgaard4a31a932013-12-10 09:45:00 -03002304 if (edid->blocks > 2) {
2305 edid->blocks = 2;
Hans Verkuil54450f52012-07-18 05:45:16 -03002306 return -E2BIG;
Mats Randgaard4a31a932013-12-10 09:45:00 -03002307 }
Hans Verkuil41a52372015-09-07 08:12:57 -03002308 pa = cec_get_edid_phys_addr(edid->edid, edid->blocks * 128, &spa_loc);
2309 err = cec_phys_addr_validate(pa, &pa, NULL);
2310 if (err)
2311 return err;
Mats Randgaard4a31a932013-12-10 09:45:00 -03002312
Mats Randgaarddd08beb2013-12-10 09:57:09 -03002313 v4l2_dbg(2, debug, sd, "%s: write EDID pad %d, edid.present = 0x%x\n",
2314 __func__, edid->pad, state->edid.present);
2315
Mats Randgaard3e86aa82013-12-10 09:55:18 -03002316 /* Disable hotplug and I2C access to EDID RAM from DDC port */
Mats Randgaard4a31a932013-12-10 09:45:00 -03002317 cancel_delayed_work_sync(&state->delayed_work_enable_hotplug);
Pablo Antonb44b2e02015-02-03 14:13:18 -03002318 adv76xx_set_hpd(state, 0);
Laurent Pinchart22d97e52014-01-30 17:17:42 -03002319 rep_write_clr_set(sd, info->edid_enable_reg, 0x0f, 0x00);
Mats Randgaard3e86aa82013-12-10 09:55:18 -03002320
Hans Verkuil41a52372015-09-07 08:12:57 -03002321 /*
2322 * Return an error if no location of the source physical address
2323 * was found.
2324 */
2325 if (spa_loc == 0)
2326 return -EINVAL;
Mats Randgaarddd08beb2013-12-10 09:57:09 -03002327
Mats Randgaard3e86aa82013-12-10 09:55:18 -03002328 switch (edid->pad) {
Pablo Antonb44b2e02015-02-03 14:13:18 -03002329 case ADV76XX_PAD_HDMI_PORT_A:
Mats Randgaarddd08beb2013-12-10 09:57:09 -03002330 state->spa_port_a[0] = edid->edid[spa_loc];
2331 state->spa_port_a[1] = edid->edid[spa_loc + 1];
Mats Randgaard3e86aa82013-12-10 09:55:18 -03002332 break;
Laurent Pinchartc784b1e2014-01-29 10:08:58 -03002333 case ADV7604_PAD_HDMI_PORT_B:
Mats Randgaarddd08beb2013-12-10 09:57:09 -03002334 rep_write(sd, 0x70, edid->edid[spa_loc]);
2335 rep_write(sd, 0x71, edid->edid[spa_loc + 1]);
Mats Randgaard3e86aa82013-12-10 09:55:18 -03002336 break;
Laurent Pinchartc784b1e2014-01-29 10:08:58 -03002337 case ADV7604_PAD_HDMI_PORT_C:
Mats Randgaarddd08beb2013-12-10 09:57:09 -03002338 rep_write(sd, 0x72, edid->edid[spa_loc]);
2339 rep_write(sd, 0x73, edid->edid[spa_loc + 1]);
Mats Randgaard3e86aa82013-12-10 09:55:18 -03002340 break;
Laurent Pinchartc784b1e2014-01-29 10:08:58 -03002341 case ADV7604_PAD_HDMI_PORT_D:
Mats Randgaarddd08beb2013-12-10 09:57:09 -03002342 rep_write(sd, 0x74, edid->edid[spa_loc]);
2343 rep_write(sd, 0x75, edid->edid[spa_loc + 1]);
Mats Randgaard3e86aa82013-12-10 09:55:18 -03002344 break;
Mats Randgaarddd08beb2013-12-10 09:57:09 -03002345 default:
2346 return -EINVAL;
Mats Randgaard3e86aa82013-12-10 09:55:18 -03002347 }
Lars-Peter Clausend42010a2013-11-25 15:45:07 -03002348
2349 if (info->type == ADV7604) {
2350 rep_write(sd, 0x76, spa_loc & 0xff);
Laurent Pinchart22d97e52014-01-30 17:17:42 -03002351 rep_write_clr_set(sd, 0x77, 0x40, (spa_loc & 0x100) >> 2);
Lars-Peter Clausend42010a2013-11-25 15:45:07 -03002352 } else {
Ulrich Hechtb5a442a2016-02-17 12:57:56 -02002353 /* ADV7612 Software Manual Rev. A, p. 15 */
2354 rep_write(sd, 0x70, spa_loc & 0xff);
Laurent Pinchart22d97e52014-01-30 17:17:42 -03002355 rep_write_clr_set(sd, 0x71, 0x01, (spa_loc & 0x100) >> 8);
Lars-Peter Clausend42010a2013-11-25 15:45:07 -03002356 }
Mats Randgaard3e86aa82013-12-10 09:55:18 -03002357
Mats Randgaarddd08beb2013-12-10 09:57:09 -03002358 edid->edid[spa_loc] = state->spa_port_a[0];
2359 edid->edid[spa_loc + 1] = state->spa_port_a[1];
Mats Randgaard4a31a932013-12-10 09:45:00 -03002360
2361 memcpy(state->edid.edid, edid->edid, 128 * edid->blocks);
2362 state->edid.blocks = edid->blocks;
Hans Verkuil54450f52012-07-18 05:45:16 -03002363 state->aspect_ratio = v4l2_calc_aspect_ratio(edid->edid[0x15],
2364 edid->edid[0x16]);
Mats Randgaard3e86aa82013-12-10 09:55:18 -03002365 state->edid.present |= 1 << edid->pad;
Mats Randgaard4a31a932013-12-10 09:45:00 -03002366
2367 err = edid_write_block(sd, 128 * edid->blocks, state->edid.edid);
2368 if (err < 0) {
Mats Randgaard3e86aa82013-12-10 09:55:18 -03002369 v4l2_err(sd, "error %d writing edid pad %d\n", err, edid->pad);
Mats Randgaard4a31a932013-12-10 09:45:00 -03002370 return err;
2371 }
2372
Pablo Antonb44b2e02015-02-03 14:13:18 -03002373 /* adv76xx calculates the checksums and enables I2C access to internal
Mats Randgaarddd08beb2013-12-10 09:57:09 -03002374 EDID RAM from DDC port. */
Laurent Pinchart22d97e52014-01-30 17:17:42 -03002375 rep_write_clr_set(sd, info->edid_enable_reg, 0x0f, state->edid.present);
Mats Randgaarddd08beb2013-12-10 09:57:09 -03002376
2377 for (i = 0; i < 1000; i++) {
Lars-Peter Clausend42010a2013-11-25 15:45:07 -03002378 if (rep_read(sd, info->edid_status_reg) & state->edid.present)
Mats Randgaarddd08beb2013-12-10 09:57:09 -03002379 break;
2380 mdelay(1);
2381 }
2382 if (i == 1000) {
2383 v4l2_err(sd, "error enabling edid (0x%x)\n", state->edid.present);
2384 return -EIO;
2385 }
Hans Verkuil41a52372015-09-07 08:12:57 -03002386 cec_s_phys_addr(state->cec_adap, pa, false);
Mats Randgaarddd08beb2013-12-10 09:57:09 -03002387
Mats Randgaard4a31a932013-12-10 09:45:00 -03002388 /* enable hotplug after 100 ms */
Bhaktipriya Shridhar0423ff92016-07-02 07:43:55 -03002389 schedule_delayed_work(&state->delayed_work_enable_hotplug, HZ / 10);
Mats Randgaard4a31a932013-12-10 09:45:00 -03002390 return 0;
Hans Verkuil54450f52012-07-18 05:45:16 -03002391}
2392
2393/*********** avi info frame CEA-861-E **************/
2394
Hans Verkuil516613c2015-06-07 07:32:33 -03002395static const struct adv76xx_cfg_read_infoframe adv76xx_cri[] = {
2396 { "AVI", 0x01, 0xe0, 0x00 },
2397 { "Audio", 0x02, 0xe3, 0x1c },
2398 { "SDP", 0x04, 0xe6, 0x2a },
2399 { "Vendor", 0x10, 0xec, 0x54 }
2400};
2401
2402static int adv76xx_read_infoframe(struct v4l2_subdev *sd, int index,
2403 union hdmi_infoframe *frame)
2404{
2405 uint8_t buffer[32];
2406 u8 len;
2407 int i;
2408
2409 if (!(io_read(sd, 0x60) & adv76xx_cri[index].present_mask)) {
2410 v4l2_info(sd, "%s infoframe not received\n",
2411 adv76xx_cri[index].desc);
2412 return -ENOENT;
2413 }
2414
2415 for (i = 0; i < 3; i++)
2416 buffer[i] = infoframe_read(sd,
2417 adv76xx_cri[index].head_addr + i);
2418
2419 len = buffer[2] + 1;
2420
2421 if (len + 3 > sizeof(buffer)) {
2422 v4l2_err(sd, "%s: invalid %s infoframe length %d\n", __func__,
2423 adv76xx_cri[index].desc, len);
2424 return -ENOENT;
2425 }
2426
2427 for (i = 0; i < len; i++)
2428 buffer[i + 3] = infoframe_read(sd,
2429 adv76xx_cri[index].payload_addr + i);
2430
2431 if (hdmi_infoframe_unpack(frame, buffer) < 0) {
2432 v4l2_err(sd, "%s: unpack of %s infoframe failed\n", __func__,
2433 adv76xx_cri[index].desc);
2434 return -ENOENT;
2435 }
2436 return 0;
2437}
2438
2439static void adv76xx_log_infoframes(struct v4l2_subdev *sd)
Hans Verkuil54450f52012-07-18 05:45:16 -03002440{
2441 int i;
Hans Verkuil54450f52012-07-18 05:45:16 -03002442
Martin Buggebb88f322013-08-14 08:52:46 -03002443 if (!is_hdmi(sd)) {
Hans Verkuil516613c2015-06-07 07:32:33 -03002444 v4l2_info(sd, "receive DVI-D signal, no infoframes\n");
Hans Verkuil54450f52012-07-18 05:45:16 -03002445 return;
2446 }
2447
Hans Verkuil516613c2015-06-07 07:32:33 -03002448 for (i = 0; i < ARRAY_SIZE(adv76xx_cri); i++) {
2449 union hdmi_infoframe frame;
2450 struct i2c_client *client = v4l2_get_subdevdata(sd);
2451
2452 if (adv76xx_read_infoframe(sd, i, &frame))
2453 return;
2454 hdmi_infoframe_log(KERN_INFO, &client->dev, &frame);
Hans Verkuil54450f52012-07-18 05:45:16 -03002455 }
Hans Verkuil54450f52012-07-18 05:45:16 -03002456}
2457
Pablo Antonb44b2e02015-02-03 14:13:18 -03002458static int adv76xx_log_status(struct v4l2_subdev *sd)
Hans Verkuil54450f52012-07-18 05:45:16 -03002459{
Pablo Antonb44b2e02015-02-03 14:13:18 -03002460 struct adv76xx_state *state = to_state(sd);
2461 const struct adv76xx_chip_info *info = state->info;
Hans Verkuil54450f52012-07-18 05:45:16 -03002462 struct v4l2_dv_timings timings;
2463 struct stdi_readback stdi;
2464 u8 reg_io_0x02 = io_read(sd, 0x02);
Laurent Pinchart4a2ccdd2014-01-08 20:26:55 -03002465 u8 edid_enabled;
2466 u8 cable_det;
Hans Verkuil54450f52012-07-18 05:45:16 -03002467
Lars-Peter Clausenf216ccb2013-11-25 16:15:29 -03002468 static const char * const csc_coeff_sel_rb[16] = {
Hans Verkuil54450f52012-07-18 05:45:16 -03002469 "bypassed", "YPbPr601 -> RGB", "reserved", "YPbPr709 -> RGB",
2470 "reserved", "RGB -> YPbPr601", "reserved", "RGB -> YPbPr709",
2471 "reserved", "YPbPr709 -> YPbPr601", "YPbPr601 -> YPbPr709",
2472 "reserved", "reserved", "reserved", "reserved", "manual"
2473 };
Lars-Peter Clausenf216ccb2013-11-25 16:15:29 -03002474 static const char * const input_color_space_txt[16] = {
Hans Verkuil54450f52012-07-18 05:45:16 -03002475 "RGB limited range (16-235)", "RGB full range (0-255)",
2476 "YCbCr Bt.601 (16-235)", "YCbCr Bt.709 (16-235)",
Mats Randgaard98332392013-12-05 10:05:58 -03002477 "xvYCC Bt.601", "xvYCC Bt.709",
Hans Verkuil54450f52012-07-18 05:45:16 -03002478 "YCbCr Bt.601 (0-255)", "YCbCr Bt.709 (0-255)",
2479 "invalid", "invalid", "invalid", "invalid", "invalid",
2480 "invalid", "invalid", "automatic"
2481 };
Hans Verkuil7a5d99e2015-06-07 07:32:35 -03002482 static const char * const hdmi_color_space_txt[16] = {
2483 "RGB limited range (16-235)", "RGB full range (0-255)",
2484 "YCbCr Bt.601 (16-235)", "YCbCr Bt.709 (16-235)",
2485 "xvYCC Bt.601", "xvYCC Bt.709",
2486 "YCbCr Bt.601 (0-255)", "YCbCr Bt.709 (0-255)",
2487 "sYCC", "Adobe YCC 601", "AdobeRGB", "invalid", "invalid",
2488 "invalid", "invalid", "invalid"
2489 };
Lars-Peter Clausenf216ccb2013-11-25 16:15:29 -03002490 static const char * const rgb_quantization_range_txt[] = {
Hans Verkuil54450f52012-07-18 05:45:16 -03002491 "Automatic",
2492 "RGB limited range (16-235)",
2493 "RGB full range (0-255)",
2494 };
Lars-Peter Clausenf216ccb2013-11-25 16:15:29 -03002495 static const char * const deep_color_mode_txt[4] = {
Martin Buggebb88f322013-08-14 08:52:46 -03002496 "8-bits per channel",
2497 "10-bits per channel",
2498 "12-bits per channel",
2499 "16-bits per channel (not supported)"
2500 };
Hans Verkuil54450f52012-07-18 05:45:16 -03002501
2502 v4l2_info(sd, "-----Chip status-----\n");
2503 v4l2_info(sd, "Chip power: %s\n", no_power(sd) ? "off" : "on");
Lars-Peter Clausend42010a2013-11-25 15:45:07 -03002504 edid_enabled = rep_read(sd, info->edid_status_reg);
Mats Randgaard4a31a932013-12-10 09:45:00 -03002505 v4l2_info(sd, "EDID enabled port A: %s, B: %s, C: %s, D: %s\n",
Laurent Pinchart4a2ccdd2014-01-08 20:26:55 -03002506 ((edid_enabled & 0x01) ? "Yes" : "No"),
2507 ((edid_enabled & 0x02) ? "Yes" : "No"),
2508 ((edid_enabled & 0x04) ? "Yes" : "No"),
2509 ((edid_enabled & 0x08) ? "Yes" : "No"));
Hans Verkuil41a52372015-09-07 08:12:57 -03002510 v4l2_info(sd, "CEC: %s\n", state->cec_enabled_adap ?
Hans Verkuil54450f52012-07-18 05:45:16 -03002511 "enabled" : "disabled");
Hans Verkuil41a52372015-09-07 08:12:57 -03002512 if (state->cec_enabled_adap) {
2513 int i;
2514
2515 for (i = 0; i < ADV76XX_MAX_ADDRS; i++) {
2516 bool is_valid = state->cec_valid_addrs & (1 << i);
2517
2518 if (is_valid)
2519 v4l2_info(sd, "CEC Logical Address: 0x%x\n",
2520 state->cec_addr[i]);
2521 }
2522 }
Hans Verkuil54450f52012-07-18 05:45:16 -03002523
2524 v4l2_info(sd, "-----Signal status-----\n");
Lars-Peter Clausend42010a2013-11-25 15:45:07 -03002525 cable_det = info->read_cable_det(sd);
Mats Randgaard4a31a932013-12-10 09:45:00 -03002526 v4l2_info(sd, "Cable detected (+5V power) port A: %s, B: %s, C: %s, D: %s\n",
Lars-Peter Clausend42010a2013-11-25 15:45:07 -03002527 ((cable_det & 0x01) ? "Yes" : "No"),
2528 ((cable_det & 0x02) ? "Yes" : "No"),
Laurent Pinchart4a2ccdd2014-01-08 20:26:55 -03002529 ((cable_det & 0x04) ? "Yes" : "No"),
Lars-Peter Clausend42010a2013-11-25 15:45:07 -03002530 ((cable_det & 0x08) ? "Yes" : "No"));
Hans Verkuil54450f52012-07-18 05:45:16 -03002531 v4l2_info(sd, "TMDS signal detected: %s\n",
2532 no_signal_tmds(sd) ? "false" : "true");
2533 v4l2_info(sd, "TMDS signal locked: %s\n",
2534 no_lock_tmds(sd) ? "false" : "true");
2535 v4l2_info(sd, "SSPD locked: %s\n", no_lock_sspd(sd) ? "false" : "true");
2536 v4l2_info(sd, "STDI locked: %s\n", no_lock_stdi(sd) ? "false" : "true");
2537 v4l2_info(sd, "CP locked: %s\n", no_lock_cp(sd) ? "false" : "true");
2538 v4l2_info(sd, "CP free run: %s\n",
jean-michel.hautbois@vodalys.com58514622015-02-06 11:37:58 -03002539 (in_free_run(sd)) ? "on" : "off");
Hans Verkuilccbd5bc2012-10-16 10:02:05 -03002540 v4l2_info(sd, "Prim-mode = 0x%x, video std = 0x%x, v_freq = 0x%x\n",
2541 io_read(sd, 0x01) & 0x0f, io_read(sd, 0x00) & 0x3f,
2542 (io_read(sd, 0x01) & 0x70) >> 4);
Hans Verkuil54450f52012-07-18 05:45:16 -03002543
2544 v4l2_info(sd, "-----Video Timings-----\n");
2545 if (read_stdi(sd, &stdi))
2546 v4l2_info(sd, "STDI: not locked\n");
2547 else
2548 v4l2_info(sd, "STDI: lcf (frame height - 1) = %d, bl = %d, lcvs (vsync) = %d, %s, %chsync, %cvsync\n",
2549 stdi.lcf, stdi.bl, stdi.lcvs,
2550 stdi.interlaced ? "interlaced" : "progressive",
2551 stdi.hs_pol, stdi.vs_pol);
Pablo Antonb44b2e02015-02-03 14:13:18 -03002552 if (adv76xx_query_dv_timings(sd, &timings))
Hans Verkuil54450f52012-07-18 05:45:16 -03002553 v4l2_info(sd, "No video detected\n");
2554 else
Hans Verkuil11d034c2013-08-15 08:05:59 -03002555 v4l2_print_dv_timings(sd->name, "Detected format: ",
2556 &timings, true);
2557 v4l2_print_dv_timings(sd->name, "Configured format: ",
2558 &state->timings, true);
Hans Verkuil54450f52012-07-18 05:45:16 -03002559
Mats Randgaard76eb2d32013-08-14 08:56:57 -03002560 if (no_signal(sd))
2561 return 0;
2562
Hans Verkuil54450f52012-07-18 05:45:16 -03002563 v4l2_info(sd, "-----Color space-----\n");
2564 v4l2_info(sd, "RGB quantization range ctrl: %s\n",
2565 rgb_quantization_range_txt[state->rgb_quantization_range]);
2566 v4l2_info(sd, "Input color space: %s\n",
2567 input_color_space_txt[reg_io_0x02 >> 4]);
Hans Verkuilfd742462016-06-28 11:43:01 -03002568 v4l2_info(sd, "Output color space: %s %s, alt-gamma %s\n",
Hans Verkuil54450f52012-07-18 05:45:16 -03002569 (reg_io_0x02 & 0x02) ? "RGB" : "YCbCr",
Hans Verkuil5dd7d882015-06-07 07:32:34 -03002570 (((reg_io_0x02 >> 2) & 0x01) ^ (reg_io_0x02 & 0x01)) ?
Hans Verkuilfd742462016-06-28 11:43:01 -03002571 "(16-235)" : "(0-255)",
Hans Verkuil7a5d99e2015-06-07 07:32:35 -03002572 (reg_io_0x02 & 0x08) ? "enabled" : "disabled");
Hans Verkuil54450f52012-07-18 05:45:16 -03002573 v4l2_info(sd, "Color space conversion: %s\n",
jean-michel.hautbois@vodalys.com80f49442015-02-04 11:16:00 -03002574 csc_coeff_sel_rb[cp_read(sd, info->cp_csc) >> 4]);
Hans Verkuil54450f52012-07-18 05:45:16 -03002575
Mats Randgaard4a31a932013-12-10 09:45:00 -03002576 if (!is_digital_input(sd))
Mats Randgaard76eb2d32013-08-14 08:56:57 -03002577 return 0;
2578
2579 v4l2_info(sd, "-----%s status-----\n", is_hdmi(sd) ? "HDMI" : "DVI-D");
Mats Randgaard4a31a932013-12-10 09:45:00 -03002580 v4l2_info(sd, "Digital video port selected: %c\n",
2581 (hdmi_read(sd, 0x00) & 0x03) + 'A');
2582 v4l2_info(sd, "HDCP encrypted content: %s\n",
2583 (hdmi_read(sd, 0x05) & 0x40) ? "true" : "false");
Mats Randgaard76eb2d32013-08-14 08:56:57 -03002584 v4l2_info(sd, "HDCP keys read: %s%s\n",
2585 (hdmi_read(sd, 0x04) & 0x20) ? "yes" : "no",
2586 (hdmi_read(sd, 0x04) & 0x10) ? "ERROR" : "");
Hans Verkuil77639ff2014-09-12 06:02:02 -03002587 if (is_hdmi(sd)) {
Mats Randgaard76eb2d32013-08-14 08:56:57 -03002588 bool audio_pll_locked = hdmi_read(sd, 0x04) & 0x01;
2589 bool audio_sample_packet_detect = hdmi_read(sd, 0x18) & 0x01;
2590 bool audio_mute = io_read(sd, 0x65) & 0x40;
2591
2592 v4l2_info(sd, "Audio: pll %s, samples %s, %s\n",
2593 audio_pll_locked ? "locked" : "not locked",
2594 audio_sample_packet_detect ? "detected" : "not detected",
2595 audio_mute ? "muted" : "enabled");
2596 if (audio_pll_locked && audio_sample_packet_detect) {
2597 v4l2_info(sd, "Audio format: %s\n",
2598 (hdmi_read(sd, 0x07) & 0x20) ? "multi-channel" : "stereo");
2599 }
2600 v4l2_info(sd, "Audio CTS: %u\n", (hdmi_read(sd, 0x5b) << 12) +
2601 (hdmi_read(sd, 0x5c) << 8) +
2602 (hdmi_read(sd, 0x5d) & 0xf0));
2603 v4l2_info(sd, "Audio N: %u\n", ((hdmi_read(sd, 0x5d) & 0x0f) << 16) +
2604 (hdmi_read(sd, 0x5e) << 8) +
2605 hdmi_read(sd, 0x5f));
2606 v4l2_info(sd, "AV Mute: %s\n", (hdmi_read(sd, 0x04) & 0x40) ? "on" : "off");
2607
2608 v4l2_info(sd, "Deep color mode: %s\n", deep_color_mode_txt[(hdmi_read(sd, 0x0b) & 0x60) >> 5]);
Hans Verkuil7a5d99e2015-06-07 07:32:35 -03002609 v4l2_info(sd, "HDMI colorspace: %s\n", hdmi_color_space_txt[hdmi_read(sd, 0x53) & 0xf]);
Mats Randgaard76eb2d32013-08-14 08:56:57 -03002610
Hans Verkuil516613c2015-06-07 07:32:33 -03002611 adv76xx_log_infoframes(sd);
Hans Verkuil54450f52012-07-18 05:45:16 -03002612 }
2613
2614 return 0;
2615}
2616
Lars-Peter Clausen6f5bcfc2015-06-24 13:50:30 -03002617static int adv76xx_subscribe_event(struct v4l2_subdev *sd,
2618 struct v4l2_fh *fh,
2619 struct v4l2_event_subscription *sub)
2620{
2621 switch (sub->type) {
2622 case V4L2_EVENT_SOURCE_CHANGE:
2623 return v4l2_src_change_event_subdev_subscribe(sd, fh, sub);
2624 case V4L2_EVENT_CTRL:
2625 return v4l2_ctrl_subdev_subscribe_event(sd, fh, sub);
2626 default:
2627 return -EINVAL;
2628 }
2629}
2630
Hans Verkuil41a52372015-09-07 08:12:57 -03002631static int adv76xx_registered(struct v4l2_subdev *sd)
2632{
2633 struct adv76xx_state *state = to_state(sd);
Hans Verkuilf51e8082016-11-25 06:23:34 -02002634 struct i2c_client *client = v4l2_get_subdevdata(sd);
Hans Verkuil41a52372015-09-07 08:12:57 -03002635 int err;
2636
Hans Verkuilf51e8082016-11-25 06:23:34 -02002637 err = cec_register_adapter(state->cec_adap, &client->dev);
Hans Verkuil41a52372015-09-07 08:12:57 -03002638 if (err)
2639 cec_delete_adapter(state->cec_adap);
2640 return err;
2641}
2642
2643static void adv76xx_unregistered(struct v4l2_subdev *sd)
2644{
2645 struct adv76xx_state *state = to_state(sd);
2646
2647 cec_unregister_adapter(state->cec_adap);
2648}
2649
Hans Verkuil54450f52012-07-18 05:45:16 -03002650/* ----------------------------------------------------------------------- */
2651
Pablo Antonb44b2e02015-02-03 14:13:18 -03002652static const struct v4l2_ctrl_ops adv76xx_ctrl_ops = {
2653 .s_ctrl = adv76xx_s_ctrl,
Hans Verkuil297a4142016-01-27 11:31:41 -02002654 .g_volatile_ctrl = adv76xx_g_volatile_ctrl,
Hans Verkuil54450f52012-07-18 05:45:16 -03002655};
2656
Pablo Antonb44b2e02015-02-03 14:13:18 -03002657static const struct v4l2_subdev_core_ops adv76xx_core_ops = {
2658 .log_status = adv76xx_log_status,
2659 .interrupt_service_routine = adv76xx_isr,
Lars-Peter Clausen6f5bcfc2015-06-24 13:50:30 -03002660 .subscribe_event = adv76xx_subscribe_event,
Lars-Peter Clausen09756262015-06-24 13:50:27 -03002661 .unsubscribe_event = v4l2_event_subdev_unsubscribe,
Hans Verkuil54450f52012-07-18 05:45:16 -03002662#ifdef CONFIG_VIDEO_ADV_DEBUG
Pablo Antonb44b2e02015-02-03 14:13:18 -03002663 .g_register = adv76xx_g_register,
2664 .s_register = adv76xx_s_register,
Hans Verkuil54450f52012-07-18 05:45:16 -03002665#endif
2666};
2667
Pablo Antonb44b2e02015-02-03 14:13:18 -03002668static const struct v4l2_subdev_video_ops adv76xx_video_ops = {
2669 .s_routing = adv76xx_s_routing,
2670 .g_input_status = adv76xx_g_input_status,
2671 .s_dv_timings = adv76xx_s_dv_timings,
2672 .g_dv_timings = adv76xx_g_dv_timings,
2673 .query_dv_timings = adv76xx_query_dv_timings,
Hans Verkuil54450f52012-07-18 05:45:16 -03002674};
2675
Pablo Antonb44b2e02015-02-03 14:13:18 -03002676static const struct v4l2_subdev_pad_ops adv76xx_pad_ops = {
2677 .enum_mbus_code = adv76xx_enum_mbus_code,
Ulrich Hechtb7d4d2f2015-12-22 12:22:01 -02002678 .get_selection = adv76xx_get_selection,
Pablo Antonb44b2e02015-02-03 14:13:18 -03002679 .get_fmt = adv76xx_get_format,
2680 .set_fmt = adv76xx_set_format,
2681 .get_edid = adv76xx_get_edid,
2682 .set_edid = adv76xx_set_edid,
2683 .dv_timings_cap = adv76xx_dv_timings_cap,
2684 .enum_dv_timings = adv76xx_enum_dv_timings,
Hans Verkuil54450f52012-07-18 05:45:16 -03002685};
2686
Pablo Antonb44b2e02015-02-03 14:13:18 -03002687static const struct v4l2_subdev_ops adv76xx_ops = {
2688 .core = &adv76xx_core_ops,
2689 .video = &adv76xx_video_ops,
2690 .pad = &adv76xx_pad_ops,
Hans Verkuil54450f52012-07-18 05:45:16 -03002691};
2692
Hans Verkuil41a52372015-09-07 08:12:57 -03002693static const struct v4l2_subdev_internal_ops adv76xx_int_ops = {
2694 .registered = adv76xx_registered,
2695 .unregistered = adv76xx_unregistered,
2696};
2697
Hans Verkuil54450f52012-07-18 05:45:16 -03002698/* -------------------------- custom ctrls ---------------------------------- */
2699
2700static const struct v4l2_ctrl_config adv7604_ctrl_analog_sampling_phase = {
Pablo Antonb44b2e02015-02-03 14:13:18 -03002701 .ops = &adv76xx_ctrl_ops,
Hans Verkuil54450f52012-07-18 05:45:16 -03002702 .id = V4L2_CID_ADV_RX_ANALOG_SAMPLING_PHASE,
2703 .name = "Analog Sampling Phase",
2704 .type = V4L2_CTRL_TYPE_INTEGER,
2705 .min = 0,
2706 .max = 0x1f,
2707 .step = 1,
2708 .def = 0,
2709};
2710
Pablo Antonb44b2e02015-02-03 14:13:18 -03002711static const struct v4l2_ctrl_config adv76xx_ctrl_free_run_color_manual = {
2712 .ops = &adv76xx_ctrl_ops,
Hans Verkuil54450f52012-07-18 05:45:16 -03002713 .id = V4L2_CID_ADV_RX_FREE_RUN_COLOR_MANUAL,
2714 .name = "Free Running Color, Manual",
2715 .type = V4L2_CTRL_TYPE_BOOLEAN,
2716 .min = false,
2717 .max = true,
2718 .step = 1,
2719 .def = false,
2720};
2721
Pablo Antonb44b2e02015-02-03 14:13:18 -03002722static const struct v4l2_ctrl_config adv76xx_ctrl_free_run_color = {
2723 .ops = &adv76xx_ctrl_ops,
Hans Verkuil54450f52012-07-18 05:45:16 -03002724 .id = V4L2_CID_ADV_RX_FREE_RUN_COLOR,
2725 .name = "Free Running Color",
2726 .type = V4L2_CTRL_TYPE_INTEGER,
2727 .min = 0x0,
2728 .max = 0xffffff,
2729 .step = 0x1,
2730 .def = 0x0,
2731};
2732
2733/* ----------------------------------------------------------------------- */
2734
Pablo Antonb44b2e02015-02-03 14:13:18 -03002735static int adv76xx_core_init(struct v4l2_subdev *sd)
Hans Verkuil54450f52012-07-18 05:45:16 -03002736{
Pablo Antonb44b2e02015-02-03 14:13:18 -03002737 struct adv76xx_state *state = to_state(sd);
2738 const struct adv76xx_chip_info *info = state->info;
2739 struct adv76xx_platform_data *pdata = &state->pdata;
Hans Verkuil54450f52012-07-18 05:45:16 -03002740
2741 hdmi_write(sd, 0x48,
2742 (pdata->disable_pwrdnb ? 0x80 : 0) |
2743 (pdata->disable_cable_det_rst ? 0x40 : 0));
2744
2745 disable_input(sd);
2746
Laurent Pinchart5ef54b52014-01-31 10:57:27 -03002747 if (pdata->default_input >= 0 &&
2748 pdata->default_input < state->source_pad) {
2749 state->selected_input = pdata->default_input;
2750 select_input(sd);
2751 enable_input(sd);
2752 }
2753
Hans Verkuil54450f52012-07-18 05:45:16 -03002754 /* power */
2755 io_write(sd, 0x0c, 0x42); /* Power up part and power down VDP */
2756 io_write(sd, 0x0b, 0x44); /* Power down ESDP block */
2757 cp_write(sd, 0xcf, 0x01); /* Power down macrovision */
2758
2759 /* video format */
Hans Verkuilfd742462016-06-28 11:43:01 -03002760 io_write_clr_set(sd, 0x02, 0x0f, pdata->alt_gamma << 3);
Laurent Pinchart22d97e52014-01-30 17:17:42 -03002761 io_write_clr_set(sd, 0x05, 0x0e, pdata->blank_data << 3 |
Laurent Pinchart539b33b2014-01-26 18:42:37 -03002762 pdata->insert_av_codes << 2 |
2763 pdata->replicate_av_codes << 1);
Pablo Antonb44b2e02015-02-03 14:13:18 -03002764 adv76xx_setup_format(state);
Hans Verkuil54450f52012-07-18 05:45:16 -03002765
Hans Verkuil54450f52012-07-18 05:45:16 -03002766 cp_write(sd, 0x69, 0x30); /* Enable CP CSC */
Martin Bugge98908692013-12-20 05:14:57 -03002767
2768 /* VS, HS polarities */
Laurent Pinchart1b5ab872014-02-04 19:57:56 -03002769 io_write(sd, 0x06, 0xa0 | pdata->inv_vs_pol << 2 |
2770 pdata->inv_hs_pol << 1 | pdata->inv_llc_pol);
Mikhail Khelikf31b62e2013-12-20 05:12:00 -03002771
2772 /* Adjust drive strength */
2773 io_write(sd, 0x14, 0x40 | pdata->dr_str_data << 4 |
2774 pdata->dr_str_clk << 2 |
2775 pdata->dr_str_sync);
2776
Hans Verkuil54450f52012-07-18 05:45:16 -03002777 cp_write(sd, 0xba, (pdata->hdmi_free_run_mode << 1) | 0x01); /* HDMI free run */
2778 cp_write(sd, 0xf3, 0xdc); /* Low threshold to enter/exit free run mode */
2779 cp_write(sd, 0xf9, 0x23); /* STDI ch. 1 - LCVS change threshold -
Hans Verkuil80939642012-10-16 05:46:21 -03002780 ADI recommended setting [REF_01, c. 2.3.3] */
Hans Verkuil54450f52012-07-18 05:45:16 -03002781 cp_write(sd, 0x45, 0x23); /* STDI ch. 2 - LCVS change threshold -
Hans Verkuil80939642012-10-16 05:46:21 -03002782 ADI recommended setting [REF_01, c. 2.3.3] */
Hans Verkuil54450f52012-07-18 05:45:16 -03002783 cp_write(sd, 0xc9, 0x2d); /* use prim_mode and vid_std as free run resolution
2784 for digital formats */
2785
Mats Randgaard5474b982013-12-05 10:33:41 -03002786 /* HDMI audio */
Laurent Pinchart22d97e52014-01-30 17:17:42 -03002787 hdmi_write_clr_set(sd, 0x15, 0x03, 0x03); /* Mute on FIFO over-/underflow [REF_01, c. 1.2.18] */
2788 hdmi_write_clr_set(sd, 0x1a, 0x0e, 0x08); /* Wait 1 s before unmute */
2789 hdmi_write_clr_set(sd, 0x68, 0x06, 0x06); /* FIFO reset on over-/underflow [REF_01, c. 1.2.19] */
Mats Randgaard5474b982013-12-05 10:33:41 -03002790
Hans Verkuil54450f52012-07-18 05:45:16 -03002791 /* TODO from platform data */
2792 afe_write(sd, 0xb5, 0x01); /* Setting MCLK to 256Fs */
2793
Pablo Antonb44b2e02015-02-03 14:13:18 -03002794 if (adv76xx_has_afe(state)) {
Lars-Peter Clausend42010a2013-11-25 15:45:07 -03002795 afe_write(sd, 0x02, pdata->ain_sel); /* Select analog input muxing mode */
Laurent Pinchart22d97e52014-01-30 17:17:42 -03002796 io_write_clr_set(sd, 0x30, 1 << 4, pdata->output_bus_lsb_to_msb << 4);
Lars-Peter Clausend42010a2013-11-25 15:45:07 -03002797 }
Hans Verkuil54450f52012-07-18 05:45:16 -03002798
Hans Verkuil54450f52012-07-18 05:45:16 -03002799 /* interrupts */
Lars-Peter Clausend42010a2013-11-25 15:45:07 -03002800 io_write(sd, 0x40, 0xc0 | pdata->int1_config); /* Configure INT1 */
Hans Verkuil54450f52012-07-18 05:45:16 -03002801 io_write(sd, 0x46, 0x98); /* Enable SSPD, STDI and CP unlocked interrupts */
Lars-Peter Clausend42010a2013-11-25 15:45:07 -03002802 io_write(sd, 0x6e, info->fmt_change_digital_mask); /* Enable V_LOCKED and DE_REGEN_LCK interrupts */
2803 io_write(sd, 0x73, info->cable_det_mask); /* Enable cable detection (+5v) interrupts */
2804 info->setup_irqs(sd);
Hans Verkuil54450f52012-07-18 05:45:16 -03002805
2806 return v4l2_ctrl_handler_setup(sd->ctrl_handler);
2807}
2808
Lars-Peter Clausend42010a2013-11-25 15:45:07 -03002809static void adv7604_setup_irqs(struct v4l2_subdev *sd)
2810{
2811 io_write(sd, 0x41, 0xd7); /* STDI irq for any change, disable INT2 */
2812}
2813
2814static void adv7611_setup_irqs(struct v4l2_subdev *sd)
2815{
2816 io_write(sd, 0x41, 0xd0); /* STDI irq for any change, disable INT2 */
2817}
2818
William Towle8331d302015-06-03 10:59:51 -03002819static void adv7612_setup_irqs(struct v4l2_subdev *sd)
2820{
2821 io_write(sd, 0x41, 0xd0); /* disable INT2 */
2822}
2823
Pablo Antonb44b2e02015-02-03 14:13:18 -03002824static void adv76xx_unregister_clients(struct adv76xx_state *state)
Hans Verkuil54450f52012-07-18 05:45:16 -03002825{
Laurent Pinchart05cacb12014-01-30 16:32:21 -03002826 unsigned int i;
2827
2828 for (i = 1; i < ARRAY_SIZE(state->i2c_clients); ++i) {
2829 if (state->i2c_clients[i])
2830 i2c_unregister_device(state->i2c_clients[i]);
2831 }
Hans Verkuil54450f52012-07-18 05:45:16 -03002832}
2833
Pablo Antonb44b2e02015-02-03 14:13:18 -03002834static struct i2c_client *adv76xx_dummy_client(struct v4l2_subdev *sd,
Hans Verkuil54450f52012-07-18 05:45:16 -03002835 u8 addr, u8 io_reg)
2836{
2837 struct i2c_client *client = v4l2_get_subdevdata(sd);
2838
2839 if (addr)
2840 io_write(sd, io_reg, addr << 1);
2841 return i2c_new_dummy(client->adapter, io_read(sd, io_reg) >> 1);
2842}
2843
Pablo Antonb44b2e02015-02-03 14:13:18 -03002844static const struct adv76xx_reg_seq adv7604_recommended_settings_afe[] = {
Lars-Peter Clausend42010a2013-11-25 15:45:07 -03002845 /* reset ADI recommended settings for HDMI: */
2846 /* "ADV7604 Register Settings Recommendations (rev. 2.5, June 2010)" p. 4. */
Pablo Antonb44b2e02015-02-03 14:13:18 -03002847 { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x0d), 0x04 }, /* HDMI filter optimization */
2848 { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x0d), 0x04 }, /* HDMI filter optimization */
2849 { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x3d), 0x00 }, /* DDC bus active pull-up control */
2850 { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x3e), 0x74 }, /* TMDS PLL optimization */
2851 { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x4e), 0x3b }, /* TMDS PLL optimization */
2852 { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x57), 0x74 }, /* TMDS PLL optimization */
2853 { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x58), 0x63 }, /* TMDS PLL optimization */
2854 { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x8d), 0x18 }, /* equaliser */
2855 { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x8e), 0x34 }, /* equaliser */
2856 { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x93), 0x88 }, /* equaliser */
2857 { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x94), 0x2e }, /* equaliser */
2858 { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x96), 0x00 }, /* enable automatic EQ changing */
Lars-Peter Clausend42010a2013-11-25 15:45:07 -03002859
2860 /* set ADI recommended settings for digitizer */
2861 /* "ADV7604 Register Settings Recommendations (rev. 2.5, June 2010)" p. 17. */
Pablo Antonb44b2e02015-02-03 14:13:18 -03002862 { ADV76XX_REG(ADV76XX_PAGE_AFE, 0x12), 0x7b }, /* ADC noise shaping filter controls */
2863 { ADV76XX_REG(ADV76XX_PAGE_AFE, 0x0c), 0x1f }, /* CP core gain controls */
2864 { ADV76XX_REG(ADV76XX_PAGE_CP, 0x3e), 0x04 }, /* CP core pre-gain control */
2865 { ADV76XX_REG(ADV76XX_PAGE_CP, 0xc3), 0x39 }, /* CP coast control. Graphics mode */
2866 { ADV76XX_REG(ADV76XX_PAGE_CP, 0x40), 0x5c }, /* CP core pre-gain control. Graphics mode */
Lars-Peter Clausend42010a2013-11-25 15:45:07 -03002867
Pablo Antonb44b2e02015-02-03 14:13:18 -03002868 { ADV76XX_REG_SEQ_TERM, 0 },
Lars-Peter Clausend42010a2013-11-25 15:45:07 -03002869};
2870
Pablo Antonb44b2e02015-02-03 14:13:18 -03002871static const struct adv76xx_reg_seq adv7604_recommended_settings_hdmi[] = {
Lars-Peter Clausend42010a2013-11-25 15:45:07 -03002872 /* set ADI recommended settings for HDMI: */
2873 /* "ADV7604 Register Settings Recommendations (rev. 2.5, June 2010)" p. 4. */
Pablo Antonb44b2e02015-02-03 14:13:18 -03002874 { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x0d), 0x84 }, /* HDMI filter optimization */
2875 { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x3d), 0x10 }, /* DDC bus active pull-up control */
2876 { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x3e), 0x39 }, /* TMDS PLL optimization */
2877 { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x4e), 0x3b }, /* TMDS PLL optimization */
2878 { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x57), 0xb6 }, /* TMDS PLL optimization */
2879 { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x58), 0x03 }, /* TMDS PLL optimization */
2880 { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x8d), 0x18 }, /* equaliser */
2881 { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x8e), 0x34 }, /* equaliser */
2882 { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x93), 0x8b }, /* equaliser */
2883 { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x94), 0x2d }, /* equaliser */
2884 { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x96), 0x01 }, /* enable automatic EQ changing */
Lars-Peter Clausend42010a2013-11-25 15:45:07 -03002885
2886 /* reset ADI recommended settings for digitizer */
2887 /* "ADV7604 Register Settings Recommendations (rev. 2.5, June 2010)" p. 17. */
Pablo Antonb44b2e02015-02-03 14:13:18 -03002888 { ADV76XX_REG(ADV76XX_PAGE_AFE, 0x12), 0xfb }, /* ADC noise shaping filter controls */
2889 { ADV76XX_REG(ADV76XX_PAGE_AFE, 0x0c), 0x0d }, /* CP core gain controls */
Lars-Peter Clausend42010a2013-11-25 15:45:07 -03002890
Pablo Antonb44b2e02015-02-03 14:13:18 -03002891 { ADV76XX_REG_SEQ_TERM, 0 },
Lars-Peter Clausend42010a2013-11-25 15:45:07 -03002892};
2893
Pablo Antonb44b2e02015-02-03 14:13:18 -03002894static const struct adv76xx_reg_seq adv7611_recommended_settings_hdmi[] = {
Lars-Peter Clausenc41ad9c2014-06-17 08:52:24 -03002895 /* ADV7611 Register Settings Recommendations Rev 1.5, May 2014 */
Pablo Antonb44b2e02015-02-03 14:13:18 -03002896 { ADV76XX_REG(ADV76XX_PAGE_CP, 0x6c), 0x00 },
2897 { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x9b), 0x03 },
2898 { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x6f), 0x08 },
2899 { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x85), 0x1f },
2900 { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x87), 0x70 },
2901 { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x57), 0xda },
2902 { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x58), 0x01 },
2903 { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x03), 0x98 },
2904 { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x4c), 0x44 },
2905 { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x8d), 0x04 },
2906 { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x8e), 0x1e },
Lars-Peter Clausend42010a2013-11-25 15:45:07 -03002907
Pablo Antonb44b2e02015-02-03 14:13:18 -03002908 { ADV76XX_REG_SEQ_TERM, 0 },
Lars-Peter Clausend42010a2013-11-25 15:45:07 -03002909};
2910
William Towle8331d302015-06-03 10:59:51 -03002911static const struct adv76xx_reg_seq adv7612_recommended_settings_hdmi[] = {
2912 { ADV76XX_REG(ADV76XX_PAGE_CP, 0x6c), 0x00 },
2913 { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x9b), 0x03 },
2914 { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x6f), 0x08 },
2915 { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x85), 0x1f },
2916 { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x87), 0x70 },
2917 { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x57), 0xda },
2918 { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x58), 0x01 },
2919 { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x03), 0x98 },
2920 { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x4c), 0x44 },
2921 { ADV76XX_REG_SEQ_TERM, 0 },
2922};
2923
Pablo Antonb44b2e02015-02-03 14:13:18 -03002924static const struct adv76xx_chip_info adv76xx_chip_info[] = {
Lars-Peter Clausend42010a2013-11-25 15:45:07 -03002925 [ADV7604] = {
2926 .type = ADV7604,
2927 .has_afe = true,
Laurent Pinchartc784b1e2014-01-29 10:08:58 -03002928 .max_port = ADV7604_PAD_VGA_COMP,
Lars-Peter Clausend42010a2013-11-25 15:45:07 -03002929 .num_dv_ports = 4,
2930 .edid_enable_reg = 0x77,
2931 .edid_status_reg = 0x7d,
2932 .lcf_reg = 0xb3,
2933 .tdms_lock_mask = 0xe0,
2934 .cable_det_mask = 0x1e,
2935 .fmt_change_digital_mask = 0xc1,
jean-michel.hautbois@vodalys.com80f49442015-02-04 11:16:00 -03002936 .cp_csc = 0xfc,
Laurent Pinchart539b33b2014-01-26 18:42:37 -03002937 .formats = adv7604_formats,
2938 .nformats = ARRAY_SIZE(adv7604_formats),
Lars-Peter Clausend42010a2013-11-25 15:45:07 -03002939 .set_termination = adv7604_set_termination,
2940 .setup_irqs = adv7604_setup_irqs,
2941 .read_hdmi_pixelclock = adv7604_read_hdmi_pixelclock,
2942 .read_cable_det = adv7604_read_cable_det,
2943 .recommended_settings = {
2944 [0] = adv7604_recommended_settings_afe,
2945 [1] = adv7604_recommended_settings_hdmi,
2946 },
2947 .num_recommended_settings = {
2948 [0] = ARRAY_SIZE(adv7604_recommended_settings_afe),
2949 [1] = ARRAY_SIZE(adv7604_recommended_settings_hdmi),
2950 },
Pablo Antonb44b2e02015-02-03 14:13:18 -03002951 .page_mask = BIT(ADV76XX_PAGE_IO) | BIT(ADV7604_PAGE_AVLINK) |
2952 BIT(ADV76XX_PAGE_CEC) | BIT(ADV76XX_PAGE_INFOFRAME) |
Lars-Peter Clausend42010a2013-11-25 15:45:07 -03002953 BIT(ADV7604_PAGE_ESDP) | BIT(ADV7604_PAGE_DPP) |
Pablo Antonb44b2e02015-02-03 14:13:18 -03002954 BIT(ADV76XX_PAGE_AFE) | BIT(ADV76XX_PAGE_REP) |
2955 BIT(ADV76XX_PAGE_EDID) | BIT(ADV76XX_PAGE_HDMI) |
2956 BIT(ADV76XX_PAGE_TEST) | BIT(ADV76XX_PAGE_CP) |
Lars-Peter Clausend42010a2013-11-25 15:45:07 -03002957 BIT(ADV7604_PAGE_VDP),
jean-michel.hautbois@vodalys.com5380baa2015-04-09 05:25:46 -03002958 .linewidth_mask = 0xfff,
2959 .field0_height_mask = 0xfff,
2960 .field1_height_mask = 0xfff,
2961 .hfrontporch_mask = 0x3ff,
2962 .hsync_mask = 0x3ff,
2963 .hbackporch_mask = 0x3ff,
2964 .field0_vfrontporch_mask = 0x1fff,
2965 .field0_vsync_mask = 0x1fff,
2966 .field0_vbackporch_mask = 0x1fff,
2967 .field1_vfrontporch_mask = 0x1fff,
2968 .field1_vsync_mask = 0x1fff,
2969 .field1_vbackporch_mask = 0x1fff,
Lars-Peter Clausend42010a2013-11-25 15:45:07 -03002970 },
2971 [ADV7611] = {
2972 .type = ADV7611,
2973 .has_afe = false,
Pablo Antonb44b2e02015-02-03 14:13:18 -03002974 .max_port = ADV76XX_PAD_HDMI_PORT_A,
Lars-Peter Clausend42010a2013-11-25 15:45:07 -03002975 .num_dv_ports = 1,
2976 .edid_enable_reg = 0x74,
2977 .edid_status_reg = 0x76,
2978 .lcf_reg = 0xa3,
2979 .tdms_lock_mask = 0x43,
2980 .cable_det_mask = 0x01,
2981 .fmt_change_digital_mask = 0x03,
jean-michel.hautbois@vodalys.com80f49442015-02-04 11:16:00 -03002982 .cp_csc = 0xf4,
Laurent Pinchart539b33b2014-01-26 18:42:37 -03002983 .formats = adv7611_formats,
2984 .nformats = ARRAY_SIZE(adv7611_formats),
Lars-Peter Clausend42010a2013-11-25 15:45:07 -03002985 .set_termination = adv7611_set_termination,
2986 .setup_irqs = adv7611_setup_irqs,
2987 .read_hdmi_pixelclock = adv7611_read_hdmi_pixelclock,
2988 .read_cable_det = adv7611_read_cable_det,
2989 .recommended_settings = {
2990 [1] = adv7611_recommended_settings_hdmi,
2991 },
2992 .num_recommended_settings = {
2993 [1] = ARRAY_SIZE(adv7611_recommended_settings_hdmi),
2994 },
Pablo Antonb44b2e02015-02-03 14:13:18 -03002995 .page_mask = BIT(ADV76XX_PAGE_IO) | BIT(ADV76XX_PAGE_CEC) |
2996 BIT(ADV76XX_PAGE_INFOFRAME) | BIT(ADV76XX_PAGE_AFE) |
2997 BIT(ADV76XX_PAGE_REP) | BIT(ADV76XX_PAGE_EDID) |
2998 BIT(ADV76XX_PAGE_HDMI) | BIT(ADV76XX_PAGE_CP),
jean-michel.hautbois@vodalys.com5380baa2015-04-09 05:25:46 -03002999 .linewidth_mask = 0x1fff,
3000 .field0_height_mask = 0x1fff,
3001 .field1_height_mask = 0x1fff,
3002 .hfrontporch_mask = 0x1fff,
3003 .hsync_mask = 0x1fff,
3004 .hbackporch_mask = 0x1fff,
3005 .field0_vfrontporch_mask = 0x3fff,
3006 .field0_vsync_mask = 0x3fff,
3007 .field0_vbackporch_mask = 0x3fff,
3008 .field1_vfrontporch_mask = 0x3fff,
3009 .field1_vsync_mask = 0x3fff,
3010 .field1_vbackporch_mask = 0x3fff,
Lars-Peter Clausend42010a2013-11-25 15:45:07 -03003011 },
William Towle8331d302015-06-03 10:59:51 -03003012 [ADV7612] = {
3013 .type = ADV7612,
3014 .has_afe = false,
William Towle7111cdd2015-07-23 09:21:34 -03003015 .max_port = ADV76XX_PAD_HDMI_PORT_A, /* B not supported */
3016 .num_dv_ports = 1, /* normally 2 */
William Towle8331d302015-06-03 10:59:51 -03003017 .edid_enable_reg = 0x74,
3018 .edid_status_reg = 0x76,
3019 .lcf_reg = 0xa3,
3020 .tdms_lock_mask = 0x43,
3021 .cable_det_mask = 0x01,
3022 .fmt_change_digital_mask = 0x03,
William Towle7111cdd2015-07-23 09:21:34 -03003023 .cp_csc = 0xf4,
William Towle8331d302015-06-03 10:59:51 -03003024 .formats = adv7612_formats,
3025 .nformats = ARRAY_SIZE(adv7612_formats),
3026 .set_termination = adv7611_set_termination,
3027 .setup_irqs = adv7612_setup_irqs,
3028 .read_hdmi_pixelclock = adv7611_read_hdmi_pixelclock,
William Towle7111cdd2015-07-23 09:21:34 -03003029 .read_cable_det = adv7612_read_cable_det,
William Towle8331d302015-06-03 10:59:51 -03003030 .recommended_settings = {
3031 [1] = adv7612_recommended_settings_hdmi,
3032 },
3033 .num_recommended_settings = {
3034 [1] = ARRAY_SIZE(adv7612_recommended_settings_hdmi),
3035 },
3036 .page_mask = BIT(ADV76XX_PAGE_IO) | BIT(ADV76XX_PAGE_CEC) |
3037 BIT(ADV76XX_PAGE_INFOFRAME) | BIT(ADV76XX_PAGE_AFE) |
3038 BIT(ADV76XX_PAGE_REP) | BIT(ADV76XX_PAGE_EDID) |
3039 BIT(ADV76XX_PAGE_HDMI) | BIT(ADV76XX_PAGE_CP),
3040 .linewidth_mask = 0x1fff,
3041 .field0_height_mask = 0x1fff,
3042 .field1_height_mask = 0x1fff,
3043 .hfrontporch_mask = 0x1fff,
3044 .hsync_mask = 0x1fff,
3045 .hbackporch_mask = 0x1fff,
3046 .field0_vfrontporch_mask = 0x3fff,
3047 .field0_vsync_mask = 0x3fff,
3048 .field0_vbackporch_mask = 0x3fff,
3049 .field1_vfrontporch_mask = 0x3fff,
3050 .field1_vsync_mask = 0x3fff,
3051 .field1_vbackporch_mask = 0x3fff,
3052 },
Lars-Peter Clausend42010a2013-11-25 15:45:07 -03003053};
3054
Fabian Frederick7f099a72015-03-16 16:54:33 -03003055static const struct i2c_device_id adv76xx_i2c_id[] = {
Pablo Antonb44b2e02015-02-03 14:13:18 -03003056 { "adv7604", (kernel_ulong_t)&adv76xx_chip_info[ADV7604] },
3057 { "adv7611", (kernel_ulong_t)&adv76xx_chip_info[ADV7611] },
William Towle8331d302015-06-03 10:59:51 -03003058 { "adv7612", (kernel_ulong_t)&adv76xx_chip_info[ADV7612] },
Laurent Pinchartf82f3132013-11-25 16:19:08 -03003059 { }
3060};
Pablo Antonb44b2e02015-02-03 14:13:18 -03003061MODULE_DEVICE_TABLE(i2c, adv76xx_i2c_id);
Laurent Pinchartf82f3132013-11-25 16:19:08 -03003062
Fabian Frederick7f099a72015-03-16 16:54:33 -03003063static const struct of_device_id adv76xx_of_id[] __maybe_unused = {
Pablo Antonb44b2e02015-02-03 14:13:18 -03003064 { .compatible = "adi,adv7611", .data = &adv76xx_chip_info[ADV7611] },
William Towle8331d302015-06-03 10:59:51 -03003065 { .compatible = "adi,adv7612", .data = &adv76xx_chip_info[ADV7612] },
Laurent Pinchartf82f3132013-11-25 16:19:08 -03003066 { }
3067};
Pablo Antonb44b2e02015-02-03 14:13:18 -03003068MODULE_DEVICE_TABLE(of, adv76xx_of_id);
Laurent Pinchartf82f3132013-11-25 16:19:08 -03003069
Pablo Antonb44b2e02015-02-03 14:13:18 -03003070static int adv76xx_parse_dt(struct adv76xx_state *state)
Laurent Pinchartf82f3132013-11-25 16:19:08 -03003071{
Laurent Pinchart6fa88042014-02-04 20:23:16 -03003072 struct v4l2_of_endpoint bus_cfg;
3073 struct device_node *endpoint;
3074 struct device_node *np;
3075 unsigned int flags;
Javier Martinez Canillas7f6cd6c2016-01-11 14:47:10 -02003076 int ret;
Ian Moltonbf9c8222015-06-03 10:59:53 -03003077 u32 v;
Laurent Pinchart6fa88042014-02-04 20:23:16 -03003078
Pablo Antonb44b2e02015-02-03 14:13:18 -03003079 np = state->i2c_clients[ADV76XX_PAGE_IO]->dev.of_node;
Laurent Pinchart6fa88042014-02-04 20:23:16 -03003080
3081 /* Parse the endpoint. */
3082 endpoint = of_graph_get_next_endpoint(np, NULL);
3083 if (!endpoint)
3084 return -EINVAL;
3085
Javier Martinez Canillas7f6cd6c2016-01-11 14:47:10 -02003086 ret = v4l2_of_parse_endpoint(endpoint, &bus_cfg);
3087 if (ret) {
3088 of_node_put(endpoint);
3089 return ret;
3090 }
Ian Moltonbf9c8222015-06-03 10:59:53 -03003091
Ulrich Hechtc57a68a2016-09-22 10:19:00 -03003092 of_node_put(endpoint);
3093
3094 if (!of_property_read_u32(np, "default-input", &v))
Ian Moltonbf9c8222015-06-03 10:59:53 -03003095 state->pdata.default_input = v;
3096 else
3097 state->pdata.default_input = -1;
3098
Laurent Pinchart6fa88042014-02-04 20:23:16 -03003099 flags = bus_cfg.bus.parallel.flags;
3100
3101 if (flags & V4L2_MBUS_HSYNC_ACTIVE_HIGH)
3102 state->pdata.inv_hs_pol = 1;
3103
3104 if (flags & V4L2_MBUS_VSYNC_ACTIVE_HIGH)
3105 state->pdata.inv_vs_pol = 1;
3106
3107 if (flags & V4L2_MBUS_PCLK_SAMPLE_RISING)
3108 state->pdata.inv_llc_pol = 1;
3109
Hans Verkuilfd742462016-06-28 11:43:01 -03003110 if (bus_cfg.bus_type == V4L2_MBUS_BT656)
Laurent Pinchart6fa88042014-02-04 20:23:16 -03003111 state->pdata.insert_av_codes = 1;
Laurent Pinchart6fa88042014-02-04 20:23:16 -03003112
Laurent Pinchartf82f3132013-11-25 16:19:08 -03003113 /* Disable the interrupt for now as no DT-based board uses it. */
Pablo Antonb44b2e02015-02-03 14:13:18 -03003114 state->pdata.int1_config = ADV76XX_INT1_CONFIG_DISABLED;
Laurent Pinchartf82f3132013-11-25 16:19:08 -03003115
3116 /* Use the default I2C addresses. */
3117 state->pdata.i2c_addresses[ADV7604_PAGE_AVLINK] = 0x42;
Pablo Antonb44b2e02015-02-03 14:13:18 -03003118 state->pdata.i2c_addresses[ADV76XX_PAGE_CEC] = 0x40;
3119 state->pdata.i2c_addresses[ADV76XX_PAGE_INFOFRAME] = 0x3e;
Laurent Pinchartf82f3132013-11-25 16:19:08 -03003120 state->pdata.i2c_addresses[ADV7604_PAGE_ESDP] = 0x38;
3121 state->pdata.i2c_addresses[ADV7604_PAGE_DPP] = 0x3c;
Pablo Antonb44b2e02015-02-03 14:13:18 -03003122 state->pdata.i2c_addresses[ADV76XX_PAGE_AFE] = 0x26;
3123 state->pdata.i2c_addresses[ADV76XX_PAGE_REP] = 0x32;
3124 state->pdata.i2c_addresses[ADV76XX_PAGE_EDID] = 0x36;
3125 state->pdata.i2c_addresses[ADV76XX_PAGE_HDMI] = 0x34;
3126 state->pdata.i2c_addresses[ADV76XX_PAGE_TEST] = 0x30;
3127 state->pdata.i2c_addresses[ADV76XX_PAGE_CP] = 0x22;
Laurent Pinchartf82f3132013-11-25 16:19:08 -03003128 state->pdata.i2c_addresses[ADV7604_PAGE_VDP] = 0x24;
3129
3130 /* Hardcode the remaining platform data fields. */
3131 state->pdata.disable_pwrdnb = 0;
3132 state->pdata.disable_cable_det_rst = 0;
Laurent Pinchartf82f3132013-11-25 16:19:08 -03003133 state->pdata.blank_data = 1;
Laurent Pinchartf82f3132013-11-25 16:19:08 -03003134 state->pdata.op_format_mode_sel = ADV7604_OP_FORMAT_MODE0;
3135 state->pdata.bus_order = ADV7604_BUS_ORDER_RGB;
Lars-Peter Clausenda8892d2016-11-29 09:23:48 -02003136 state->pdata.dr_str_data = ADV76XX_DR_STR_MEDIUM_HIGH;
3137 state->pdata.dr_str_clk = ADV76XX_DR_STR_MEDIUM_HIGH;
3138 state->pdata.dr_str_sync = ADV76XX_DR_STR_MEDIUM_HIGH;
Laurent Pinchartf82f3132013-11-25 16:19:08 -03003139
3140 return 0;
3141}
3142
Pablo Antonf862f572015-06-19 10:23:06 -03003143static const struct regmap_config adv76xx_regmap_cnf[] = {
3144 {
3145 .name = "io",
3146 .reg_bits = 8,
3147 .val_bits = 8,
3148
3149 .max_register = 0xff,
3150 .cache_type = REGCACHE_NONE,
3151 },
3152 {
3153 .name = "avlink",
3154 .reg_bits = 8,
3155 .val_bits = 8,
3156
3157 .max_register = 0xff,
3158 .cache_type = REGCACHE_NONE,
3159 },
3160 {
3161 .name = "cec",
3162 .reg_bits = 8,
3163 .val_bits = 8,
3164
3165 .max_register = 0xff,
3166 .cache_type = REGCACHE_NONE,
3167 },
3168 {
3169 .name = "infoframe",
3170 .reg_bits = 8,
3171 .val_bits = 8,
3172
3173 .max_register = 0xff,
3174 .cache_type = REGCACHE_NONE,
3175 },
3176 {
3177 .name = "esdp",
3178 .reg_bits = 8,
3179 .val_bits = 8,
3180
3181 .max_register = 0xff,
3182 .cache_type = REGCACHE_NONE,
3183 },
3184 {
3185 .name = "epp",
3186 .reg_bits = 8,
3187 .val_bits = 8,
3188
3189 .max_register = 0xff,
3190 .cache_type = REGCACHE_NONE,
3191 },
3192 {
3193 .name = "afe",
3194 .reg_bits = 8,
3195 .val_bits = 8,
3196
3197 .max_register = 0xff,
3198 .cache_type = REGCACHE_NONE,
3199 },
3200 {
3201 .name = "rep",
3202 .reg_bits = 8,
3203 .val_bits = 8,
3204
3205 .max_register = 0xff,
3206 .cache_type = REGCACHE_NONE,
3207 },
3208 {
3209 .name = "edid",
3210 .reg_bits = 8,
3211 .val_bits = 8,
3212
3213 .max_register = 0xff,
3214 .cache_type = REGCACHE_NONE,
3215 },
3216
3217 {
3218 .name = "hdmi",
3219 .reg_bits = 8,
3220 .val_bits = 8,
3221
3222 .max_register = 0xff,
3223 .cache_type = REGCACHE_NONE,
3224 },
3225 {
3226 .name = "test",
3227 .reg_bits = 8,
3228 .val_bits = 8,
3229
3230 .max_register = 0xff,
3231 .cache_type = REGCACHE_NONE,
3232 },
3233 {
3234 .name = "cp",
3235 .reg_bits = 8,
3236 .val_bits = 8,
3237
3238 .max_register = 0xff,
3239 .cache_type = REGCACHE_NONE,
3240 },
3241 {
3242 .name = "vdp",
3243 .reg_bits = 8,
3244 .val_bits = 8,
3245
3246 .max_register = 0xff,
3247 .cache_type = REGCACHE_NONE,
3248 },
3249};
3250
3251static int configure_regmap(struct adv76xx_state *state, int region)
3252{
3253 int err;
3254
3255 if (!state->i2c_clients[region])
3256 return -ENODEV;
3257
3258 state->regmap[region] =
3259 devm_regmap_init_i2c(state->i2c_clients[region],
3260 &adv76xx_regmap_cnf[region]);
3261
3262 if (IS_ERR(state->regmap[region])) {
3263 err = PTR_ERR(state->regmap[region]);
3264 v4l_err(state->i2c_clients[region],
3265 "Error initializing regmap %d with error %d\n",
3266 region, err);
3267 return -EINVAL;
3268 }
3269
3270 return 0;
3271}
3272
3273static int configure_regmaps(struct adv76xx_state *state)
3274{
3275 int i, err;
3276
3277 for (i = ADV7604_PAGE_AVLINK ; i < ADV76XX_PAGE_MAX; i++) {
3278 err = configure_regmap(state, i);
3279 if (err && (err != -ENODEV))
3280 return err;
3281 }
3282 return 0;
3283}
3284
Dragos Bogdanf5591da2016-06-22 08:30:42 -03003285static void adv76xx_reset(struct adv76xx_state *state)
3286{
3287 if (state->reset_gpio) {
3288 /* ADV76XX can be reset by a low reset pulse of minimum 5 ms. */
3289 gpiod_set_value_cansleep(state->reset_gpio, 0);
3290 usleep_range(5000, 10000);
3291 gpiod_set_value_cansleep(state->reset_gpio, 1);
3292 /* It is recommended to wait 5 ms after the low pulse before */
3293 /* an I2C write is performed to the ADV76XX. */
3294 usleep_range(5000, 10000);
3295 }
3296}
3297
Pablo Antonb44b2e02015-02-03 14:13:18 -03003298static int adv76xx_probe(struct i2c_client *client,
Hans Verkuil54450f52012-07-18 05:45:16 -03003299 const struct i2c_device_id *id)
3300{
Hans Verkuil591b72f2013-12-17 10:05:13 -03003301 static const struct v4l2_dv_timings cea640x480 =
3302 V4L2_DV_BT_CEA_640X480P59_94;
Pablo Antonb44b2e02015-02-03 14:13:18 -03003303 struct adv76xx_state *state;
Hans Verkuil54450f52012-07-18 05:45:16 -03003304 struct v4l2_ctrl_handler *hdl;
Hans Verkuil297a4142016-01-27 11:31:41 -02003305 struct v4l2_ctrl *ctrl;
Hans Verkuil54450f52012-07-18 05:45:16 -03003306 struct v4l2_subdev *sd;
Laurent Pinchartc784b1e2014-01-29 10:08:58 -03003307 unsigned int i;
Pablo Antonf862f572015-06-19 10:23:06 -03003308 unsigned int val, val2;
Hans Verkuil54450f52012-07-18 05:45:16 -03003309 int err;
3310
3311 /* Check if the adapter supports the needed features */
3312 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
3313 return -EIO;
Pablo Antonb44b2e02015-02-03 14:13:18 -03003314 v4l_dbg(1, debug, client, "detecting adv76xx client on address 0x%x\n",
Hans Verkuil54450f52012-07-18 05:45:16 -03003315 client->addr << 1);
3316
Laurent Pinchartc02b2112013-05-02 08:29:43 -03003317 state = devm_kzalloc(&client->dev, sizeof(*state), GFP_KERNEL);
Hans Verkuil54450f52012-07-18 05:45:16 -03003318 if (!state) {
Pablo Antonb44b2e02015-02-03 14:13:18 -03003319 v4l_err(client, "Could not allocate adv76xx_state memory!\n");
Hans Verkuil54450f52012-07-18 05:45:16 -03003320 return -ENOMEM;
3321 }
3322
Pablo Antonb44b2e02015-02-03 14:13:18 -03003323 state->i2c_clients[ADV76XX_PAGE_IO] = client;
Lars-Peter Clausend42010a2013-11-25 15:45:07 -03003324
Mats Randgaard25a64ac2013-08-14 07:58:45 -03003325 /* initialize variables */
3326 state->restart_stdi_once = true;
Mats Randgaardff4f80f2013-12-05 10:24:05 -03003327 state->selected_input = ~0;
Mats Randgaard25a64ac2013-08-14 07:58:45 -03003328
Laurent Pinchartf82f3132013-11-25 16:19:08 -03003329 if (IS_ENABLED(CONFIG_OF) && client->dev.of_node) {
3330 const struct of_device_id *oid;
3331
Pablo Antonb44b2e02015-02-03 14:13:18 -03003332 oid = of_match_node(adv76xx_of_id, client->dev.of_node);
Laurent Pinchartf82f3132013-11-25 16:19:08 -03003333 state->info = oid->data;
3334
Pablo Antonb44b2e02015-02-03 14:13:18 -03003335 err = adv76xx_parse_dt(state);
Laurent Pinchartf82f3132013-11-25 16:19:08 -03003336 if (err < 0) {
3337 v4l_err(client, "DT parsing error\n");
3338 return err;
3339 }
3340 } else if (client->dev.platform_data) {
Pablo Antonb44b2e02015-02-03 14:13:18 -03003341 struct adv76xx_platform_data *pdata = client->dev.platform_data;
Laurent Pinchartf82f3132013-11-25 16:19:08 -03003342
Pablo Antonb44b2e02015-02-03 14:13:18 -03003343 state->info = (const struct adv76xx_chip_info *)id->driver_data;
Laurent Pinchartf82f3132013-11-25 16:19:08 -03003344 state->pdata = *pdata;
3345 } else {
Hans Verkuil54450f52012-07-18 05:45:16 -03003346 v4l_err(client, "No platform data!\n");
Laurent Pinchartc02b2112013-05-02 08:29:43 -03003347 return -ENODEV;
Hans Verkuil54450f52012-07-18 05:45:16 -03003348 }
Laurent Pincharte9d50e92014-01-30 18:37:08 -03003349
3350 /* Request GPIOs. */
3351 for (i = 0; i < state->info->num_dv_ports; ++i) {
3352 state->hpd_gpio[i] =
Uwe Kleine-König269bd132015-03-02 04:00:44 -03003353 devm_gpiod_get_index_optional(&client->dev, "hpd", i,
3354 GPIOD_OUT_LOW);
Laurent Pincharte9d50e92014-01-30 18:37:08 -03003355 if (IS_ERR(state->hpd_gpio[i]))
Uwe Kleine-König269bd132015-03-02 04:00:44 -03003356 return PTR_ERR(state->hpd_gpio[i]);
Laurent Pincharte9d50e92014-01-30 18:37:08 -03003357
Uwe Kleine-König269bd132015-03-02 04:00:44 -03003358 if (state->hpd_gpio[i])
3359 v4l_info(client, "Handling HPD %u GPIO\n", i);
Laurent Pincharte9d50e92014-01-30 18:37:08 -03003360 }
Dragos Bogdanf5591da2016-06-22 08:30:42 -03003361 state->reset_gpio = devm_gpiod_get_optional(&client->dev, "reset",
3362 GPIOD_OUT_HIGH);
3363 if (IS_ERR(state->reset_gpio))
3364 return PTR_ERR(state->reset_gpio);
3365
3366 adv76xx_reset(state);
Laurent Pincharte9d50e92014-01-30 18:37:08 -03003367
Hans Verkuil591b72f2013-12-17 10:05:13 -03003368 state->timings = cea640x480;
Pablo Antonb44b2e02015-02-03 14:13:18 -03003369 state->format = adv76xx_format_info(state, MEDIA_BUS_FMT_YUYV8_2X8);
Hans Verkuil54450f52012-07-18 05:45:16 -03003370
3371 sd = &state->sd;
Pablo Antonb44b2e02015-02-03 14:13:18 -03003372 v4l2_i2c_subdev_init(sd, client, &adv76xx_ops);
Lars-Peter Clausend42010a2013-11-25 15:45:07 -03003373 snprintf(sd->name, sizeof(sd->name), "%s %d-%04x",
3374 id->name, i2c_adapter_id(client->adapter),
3375 client->addr);
Lars-Peter Clausen09756262015-06-24 13:50:27 -03003376 sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE | V4L2_SUBDEV_FL_HAS_EVENTS;
Hans Verkuil41a52372015-09-07 08:12:57 -03003377 sd->internal_ops = &adv76xx_int_ops;
Hans Verkuil54450f52012-07-18 05:45:16 -03003378
Pablo Antonf862f572015-06-19 10:23:06 -03003379 /* Configure IO Regmap region */
3380 err = configure_regmap(state, ADV76XX_PAGE_IO);
3381
3382 if (err) {
3383 v4l2_err(sd, "Error configuring IO regmap region\n");
3384 return -ENODEV;
3385 }
3386
Lars-Peter Clausend42010a2013-11-25 15:45:07 -03003387 /*
3388 * Verify that the chip is present. On ADV7604 the RD_INFO register only
3389 * identifies the revision, while on ADV7611 it identifies the model as
3390 * well. Use the HDMI slave address on ADV7604 and RD_INFO on ADV7611.
3391 */
William Towle8331d302015-06-03 10:59:51 -03003392 switch (state->info->type) {
3393 case ADV7604:
Pablo Antonf862f572015-06-19 10:23:06 -03003394 err = regmap_read(state->regmap[ADV76XX_PAGE_IO], 0xfb, &val);
3395 if (err) {
3396 v4l2_err(sd, "Error %d reading IO Regmap\n", err);
3397 return -ENODEV;
3398 }
Lars-Peter Clausend42010a2013-11-25 15:45:07 -03003399 if (val != 0x68) {
Pablo Antonf862f572015-06-19 10:23:06 -03003400 v4l2_err(sd, "not an adv7604 on address 0x%x\n",
Lars-Peter Clausend42010a2013-11-25 15:45:07 -03003401 client->addr << 1);
3402 return -ENODEV;
3403 }
William Towle8331d302015-06-03 10:59:51 -03003404 break;
3405 case ADV7611:
3406 case ADV7612:
Pablo Antonf862f572015-06-19 10:23:06 -03003407 err = regmap_read(state->regmap[ADV76XX_PAGE_IO],
3408 0xea,
3409 &val);
3410 if (err) {
3411 v4l2_err(sd, "Error %d reading IO Regmap\n", err);
3412 return -ENODEV;
3413 }
3414 val2 = val << 8;
3415 err = regmap_read(state->regmap[ADV76XX_PAGE_IO],
3416 0xeb,
3417 &val);
3418 if (err) {
3419 v4l2_err(sd, "Error %d reading IO Regmap\n", err);
3420 return -ENODEV;
3421 }
William Towlec1362382015-07-23 09:21:33 -03003422 val |= val2;
William Towle8331d302015-06-03 10:59:51 -03003423 if ((state->info->type == ADV7611 && val != 0x2051) ||
3424 (state->info->type == ADV7612 && val != 0x2041)) {
3425 v4l2_err(sd, "not an adv761x on address 0x%x\n",
Lars-Peter Clausend42010a2013-11-25 15:45:07 -03003426 client->addr << 1);
3427 return -ENODEV;
3428 }
William Towle8331d302015-06-03 10:59:51 -03003429 break;
Hans Verkuil54450f52012-07-18 05:45:16 -03003430 }
3431
3432 /* control handlers */
3433 hdl = &state->hdl;
Pablo Antonb44b2e02015-02-03 14:13:18 -03003434 v4l2_ctrl_handler_init(hdl, adv76xx_has_afe(state) ? 9 : 8);
Hans Verkuil54450f52012-07-18 05:45:16 -03003435
Pablo Antonb44b2e02015-02-03 14:13:18 -03003436 v4l2_ctrl_new_std(hdl, &adv76xx_ctrl_ops,
Hans Verkuil54450f52012-07-18 05:45:16 -03003437 V4L2_CID_BRIGHTNESS, -128, 127, 1, 0);
Pablo Antonb44b2e02015-02-03 14:13:18 -03003438 v4l2_ctrl_new_std(hdl, &adv76xx_ctrl_ops,
Hans Verkuil54450f52012-07-18 05:45:16 -03003439 V4L2_CID_CONTRAST, 0, 255, 1, 128);
Pablo Antonb44b2e02015-02-03 14:13:18 -03003440 v4l2_ctrl_new_std(hdl, &adv76xx_ctrl_ops,
Hans Verkuil54450f52012-07-18 05:45:16 -03003441 V4L2_CID_SATURATION, 0, 255, 1, 128);
Pablo Antonb44b2e02015-02-03 14:13:18 -03003442 v4l2_ctrl_new_std(hdl, &adv76xx_ctrl_ops,
Hans Verkuil54450f52012-07-18 05:45:16 -03003443 V4L2_CID_HUE, 0, 128, 1, 0);
Hans Verkuil297a4142016-01-27 11:31:41 -02003444 ctrl = v4l2_ctrl_new_std_menu(hdl, &adv76xx_ctrl_ops,
3445 V4L2_CID_DV_RX_IT_CONTENT_TYPE, V4L2_DV_IT_CONTENT_TYPE_NO_ITC,
3446 0, V4L2_DV_IT_CONTENT_TYPE_NO_ITC);
3447 if (ctrl)
3448 ctrl->flags |= V4L2_CTRL_FLAG_VOLATILE;
Hans Verkuil54450f52012-07-18 05:45:16 -03003449
Hans Verkuil54450f52012-07-18 05:45:16 -03003450 state->detect_tx_5v_ctrl = v4l2_ctrl_new_std(hdl, NULL,
Lars-Peter Clausend42010a2013-11-25 15:45:07 -03003451 V4L2_CID_DV_RX_POWER_PRESENT, 0,
3452 (1 << state->info->num_dv_ports) - 1, 0, 0);
Hans Verkuil54450f52012-07-18 05:45:16 -03003453 state->rgb_quantization_range_ctrl =
Pablo Antonb44b2e02015-02-03 14:13:18 -03003454 v4l2_ctrl_new_std_menu(hdl, &adv76xx_ctrl_ops,
Hans Verkuil54450f52012-07-18 05:45:16 -03003455 V4L2_CID_DV_RX_RGB_RANGE, V4L2_DV_RGB_RANGE_FULL,
3456 0, V4L2_DV_RGB_RANGE_AUTO);
Hans Verkuil54450f52012-07-18 05:45:16 -03003457
3458 /* custom controls */
Pablo Antonb44b2e02015-02-03 14:13:18 -03003459 if (adv76xx_has_afe(state))
Lars-Peter Clausend42010a2013-11-25 15:45:07 -03003460 state->analog_sampling_phase_ctrl =
3461 v4l2_ctrl_new_custom(hdl, &adv7604_ctrl_analog_sampling_phase, NULL);
Hans Verkuil54450f52012-07-18 05:45:16 -03003462 state->free_run_color_manual_ctrl =
Pablo Antonb44b2e02015-02-03 14:13:18 -03003463 v4l2_ctrl_new_custom(hdl, &adv76xx_ctrl_free_run_color_manual, NULL);
Hans Verkuil54450f52012-07-18 05:45:16 -03003464 state->free_run_color_ctrl =
Pablo Antonb44b2e02015-02-03 14:13:18 -03003465 v4l2_ctrl_new_custom(hdl, &adv76xx_ctrl_free_run_color, NULL);
Hans Verkuil54450f52012-07-18 05:45:16 -03003466
3467 sd->ctrl_handler = hdl;
3468 if (hdl->error) {
3469 err = hdl->error;
3470 goto err_hdl;
3471 }
Pablo Antonb44b2e02015-02-03 14:13:18 -03003472 if (adv76xx_s_detect_tx_5v_ctrl(sd)) {
Hans Verkuil54450f52012-07-18 05:45:16 -03003473 err = -ENODEV;
3474 goto err_hdl;
3475 }
3476
Pablo Antonb44b2e02015-02-03 14:13:18 -03003477 for (i = 1; i < ADV76XX_PAGE_MAX; ++i) {
Laurent Pinchart05cacb12014-01-30 16:32:21 -03003478 if (!(BIT(i) & state->info->page_mask))
3479 continue;
Hans Verkuil54450f52012-07-18 05:45:16 -03003480
Laurent Pinchart05cacb12014-01-30 16:32:21 -03003481 state->i2c_clients[i] =
Pablo Antonb44b2e02015-02-03 14:13:18 -03003482 adv76xx_dummy_client(sd, state->pdata.i2c_addresses[i],
Laurent Pinchart05cacb12014-01-30 16:32:21 -03003483 0xf2 + i);
3484 if (state->i2c_clients[i] == NULL) {
Lars-Peter Clausend42010a2013-11-25 15:45:07 -03003485 err = -ENOMEM;
Laurent Pinchart05cacb12014-01-30 16:32:21 -03003486 v4l2_err(sd, "failed to create i2c client %u\n", i);
Lars-Peter Clausend42010a2013-11-25 15:45:07 -03003487 goto err_i2c;
3488 }
3489 }
Laurent Pinchart05cacb12014-01-30 16:32:21 -03003490
Hans Verkuil54450f52012-07-18 05:45:16 -03003491 INIT_DELAYED_WORK(&state->delayed_work_enable_hotplug,
Pablo Antonb44b2e02015-02-03 14:13:18 -03003492 adv76xx_delayed_work_enable_hotplug);
Hans Verkuil54450f52012-07-18 05:45:16 -03003493
Laurent Pinchartc784b1e2014-01-29 10:08:58 -03003494 state->source_pad = state->info->num_dv_ports
3495 + (state->info->has_afe ? 2 : 0);
3496 for (i = 0; i < state->source_pad; ++i)
3497 state->pads[i].flags = MEDIA_PAD_FL_SINK;
3498 state->pads[state->source_pad].flags = MEDIA_PAD_FL_SOURCE;
3499
Mauro Carvalho Chehabab22e772015-12-11 07:44:40 -02003500 err = media_entity_pads_init(&sd->entity, state->source_pad + 1,
Mauro Carvalho Chehab18095102015-08-06 09:25:57 -03003501 state->pads);
Hans Verkuil54450f52012-07-18 05:45:16 -03003502 if (err)
3503 goto err_work_queues;
3504
Pablo Antonf862f572015-06-19 10:23:06 -03003505 /* Configure regmaps */
3506 err = configure_regmaps(state);
3507 if (err)
3508 goto err_entity;
3509
Pablo Antonb44b2e02015-02-03 14:13:18 -03003510 err = adv76xx_core_init(sd);
Hans Verkuil54450f52012-07-18 05:45:16 -03003511 if (err)
3512 goto err_entity;
Hans Verkuil41a52372015-09-07 08:12:57 -03003513
3514#if IS_ENABLED(CONFIG_VIDEO_ADV7604_CEC)
3515 state->cec_adap = cec_allocate_adapter(&adv76xx_cec_adap_ops,
3516 state, dev_name(&client->dev),
3517 CEC_CAP_TRANSMIT | CEC_CAP_LOG_ADDRS |
Hans Verkuilf51e8082016-11-25 06:23:34 -02003518 CEC_CAP_PASSTHROUGH | CEC_CAP_RC, ADV76XX_MAX_ADDRS);
Hans Verkuil41a52372015-09-07 08:12:57 -03003519 err = PTR_ERR_OR_ZERO(state->cec_adap);
3520 if (err)
3521 goto err_entity;
3522#endif
3523
Hans Verkuil54450f52012-07-18 05:45:16 -03003524 v4l2_info(sd, "%s found @ 0x%x (%s)\n", client->name,
3525 client->addr << 1, client->adapter->name);
Lars-Peter Clausenbedc3932013-11-25 16:18:02 -03003526
3527 err = v4l2_async_register_subdev(sd);
3528 if (err)
3529 goto err_entity;
3530
Hans Verkuil54450f52012-07-18 05:45:16 -03003531 return 0;
3532
3533err_entity:
3534 media_entity_cleanup(&sd->entity);
3535err_work_queues:
3536 cancel_delayed_work(&state->delayed_work_enable_hotplug);
Hans Verkuil54450f52012-07-18 05:45:16 -03003537err_i2c:
Pablo Antonb44b2e02015-02-03 14:13:18 -03003538 adv76xx_unregister_clients(state);
Hans Verkuil54450f52012-07-18 05:45:16 -03003539err_hdl:
3540 v4l2_ctrl_handler_free(hdl);
Hans Verkuil54450f52012-07-18 05:45:16 -03003541 return err;
3542}
3543
3544/* ----------------------------------------------------------------------- */
3545
Pablo Antonb44b2e02015-02-03 14:13:18 -03003546static int adv76xx_remove(struct i2c_client *client)
Hans Verkuil54450f52012-07-18 05:45:16 -03003547{
3548 struct v4l2_subdev *sd = i2c_get_clientdata(client);
Pablo Antonb44b2e02015-02-03 14:13:18 -03003549 struct adv76xx_state *state = to_state(sd);
Hans Verkuil54450f52012-07-18 05:45:16 -03003550
Hans Verkuil41a52372015-09-07 08:12:57 -03003551 /* disable interrupts */
3552 io_write(sd, 0x40, 0);
3553 io_write(sd, 0x41, 0);
3554 io_write(sd, 0x46, 0);
3555 io_write(sd, 0x6e, 0);
3556 io_write(sd, 0x73, 0);
3557
Hans Verkuil54450f52012-07-18 05:45:16 -03003558 cancel_delayed_work(&state->delayed_work_enable_hotplug);
Lars-Peter Clausenbedc3932013-11-25 16:18:02 -03003559 v4l2_async_unregister_subdev(sd);
Hans Verkuil54450f52012-07-18 05:45:16 -03003560 media_entity_cleanup(&sd->entity);
Pablo Antonb44b2e02015-02-03 14:13:18 -03003561 adv76xx_unregister_clients(to_state(sd));
Hans Verkuil54450f52012-07-18 05:45:16 -03003562 v4l2_ctrl_handler_free(sd->ctrl_handler);
Hans Verkuil54450f52012-07-18 05:45:16 -03003563 return 0;
3564}
3565
3566/* ----------------------------------------------------------------------- */
3567
Pablo Antonb44b2e02015-02-03 14:13:18 -03003568static struct i2c_driver adv76xx_driver = {
Hans Verkuil54450f52012-07-18 05:45:16 -03003569 .driver = {
Hans Verkuil54450f52012-07-18 05:45:16 -03003570 .name = "adv7604",
Pablo Antonb44b2e02015-02-03 14:13:18 -03003571 .of_match_table = of_match_ptr(adv76xx_of_id),
Hans Verkuil54450f52012-07-18 05:45:16 -03003572 },
Pablo Antonb44b2e02015-02-03 14:13:18 -03003573 .probe = adv76xx_probe,
3574 .remove = adv76xx_remove,
3575 .id_table = adv76xx_i2c_id,
Hans Verkuil54450f52012-07-18 05:45:16 -03003576};
3577
Pablo Antonb44b2e02015-02-03 14:13:18 -03003578module_i2c_driver(adv76xx_driver);