blob: 5dea769c3c719bd297b80e3e4391ccd6bd6b58e6 [file] [log] [blame]
Lars-Peter Clausen9c8af882012-03-05 16:30:57 +01001/*
2 * Analog Devices ADV7511 HDMI transmitter driver
3 *
4 * Copyright 2012 Analog Devices Inc.
5 *
6 * Licensed under the GPL-2.
7 */
8
9#ifndef __DRM_I2C_ADV7511_H__
10#define __DRM_I2C_ADV7511_H__
11
12#include <linux/hdmi.h>
Archit Taneja2437e7c2016-06-15 16:24:03 +053013#include <linux/i2c.h>
14#include <linux/regmap.h>
15
16#include <drm/drm_crtc_helper.h>
Lars-Peter Clausen9c8af882012-03-05 16:30:57 +010017
18#define ADV7511_REG_CHIP_REVISION 0x00
19#define ADV7511_REG_N0 0x01
20#define ADV7511_REG_N1 0x02
21#define ADV7511_REG_N2 0x03
22#define ADV7511_REG_SPDIF_FREQ 0x04
23#define ADV7511_REG_CTS_AUTOMATIC1 0x05
24#define ADV7511_REG_CTS_AUTOMATIC2 0x06
25#define ADV7511_REG_CTS_MANUAL0 0x07
26#define ADV7511_REG_CTS_MANUAL1 0x08
27#define ADV7511_REG_CTS_MANUAL2 0x09
28#define ADV7511_REG_AUDIO_SOURCE 0x0a
29#define ADV7511_REG_AUDIO_CONFIG 0x0b
30#define ADV7511_REG_I2S_CONFIG 0x0c
31#define ADV7511_REG_I2S_WIDTH 0x0d
32#define ADV7511_REG_AUDIO_SUB_SRC0 0x0e
33#define ADV7511_REG_AUDIO_SUB_SRC1 0x0f
34#define ADV7511_REG_AUDIO_SUB_SRC2 0x10
35#define ADV7511_REG_AUDIO_SUB_SRC3 0x11
36#define ADV7511_REG_AUDIO_CFG1 0x12
37#define ADV7511_REG_AUDIO_CFG2 0x13
38#define ADV7511_REG_AUDIO_CFG3 0x14
39#define ADV7511_REG_I2C_FREQ_ID_CFG 0x15
40#define ADV7511_REG_VIDEO_INPUT_CFG1 0x16
41#define ADV7511_REG_CSC_UPPER(x) (0x18 + (x) * 2)
42#define ADV7511_REG_CSC_LOWER(x) (0x19 + (x) * 2)
43#define ADV7511_REG_SYNC_DECODER(x) (0x30 + (x))
44#define ADV7511_REG_DE_GENERATOR (0x35 + (x))
45#define ADV7511_REG_PIXEL_REPETITION 0x3b
46#define ADV7511_REG_VIC_MANUAL 0x3c
47#define ADV7511_REG_VIC_SEND 0x3d
48#define ADV7511_REG_VIC_DETECTED 0x3e
49#define ADV7511_REG_AUX_VIC_DETECTED 0x3f
50#define ADV7511_REG_PACKET_ENABLE0 0x40
51#define ADV7511_REG_POWER 0x41
52#define ADV7511_REG_STATUS 0x42
53#define ADV7511_REG_EDID_I2C_ADDR 0x43
54#define ADV7511_REG_PACKET_ENABLE1 0x44
55#define ADV7511_REG_PACKET_I2C_ADDR 0x45
56#define ADV7511_REG_DSD_ENABLE 0x46
57#define ADV7511_REG_VIDEO_INPUT_CFG2 0x48
58#define ADV7511_REG_INFOFRAME_UPDATE 0x4a
59#define ADV7511_REG_GC(x) (0x4b + (x)) /* 0x4b - 0x51 */
60#define ADV7511_REG_AVI_INFOFRAME_VERSION 0x52
61#define ADV7511_REG_AVI_INFOFRAME_LENGTH 0x53
62#define ADV7511_REG_AVI_INFOFRAME_CHECKSUM 0x54
63#define ADV7511_REG_AVI_INFOFRAME(x) (0x55 + (x)) /* 0x55 - 0x6f */
64#define ADV7511_REG_AUDIO_INFOFRAME_VERSION 0x70
65#define ADV7511_REG_AUDIO_INFOFRAME_LENGTH 0x71
66#define ADV7511_REG_AUDIO_INFOFRAME_CHECKSUM 0x72
67#define ADV7511_REG_AUDIO_INFOFRAME(x) (0x73 + (x)) /* 0x73 - 0x7c */
68#define ADV7511_REG_INT_ENABLE(x) (0x94 + (x))
69#define ADV7511_REG_INT(x) (0x96 + (x))
70#define ADV7511_REG_INPUT_CLK_DIV 0x9d
71#define ADV7511_REG_PLL_STATUS 0x9e
72#define ADV7511_REG_HDMI_POWER 0xa1
73#define ADV7511_REG_HDCP_HDMI_CFG 0xaf
74#define ADV7511_REG_AN(x) (0xb0 + (x)) /* 0xb0 - 0xb7 */
75#define ADV7511_REG_HDCP_STATUS 0xb8
76#define ADV7511_REG_BCAPS 0xbe
77#define ADV7511_REG_BKSV(x) (0xc0 + (x)) /* 0xc0 - 0xc3 */
78#define ADV7511_REG_EDID_SEGMENT 0xc4
79#define ADV7511_REG_DDC_STATUS 0xc8
80#define ADV7511_REG_EDID_READ_CTRL 0xc9
81#define ADV7511_REG_BSTATUS(x) (0xca + (x)) /* 0xca - 0xcb */
82#define ADV7511_REG_TIMING_GEN_SEQ 0xd0
83#define ADV7511_REG_POWER2 0xd6
84#define ADV7511_REG_HSYNC_PLACEMENT_MSB 0xfa
85
86#define ADV7511_REG_SYNC_ADJUSTMENT(x) (0xd7 + (x)) /* 0xd7 - 0xdc */
87#define ADV7511_REG_TMDS_CLOCK_INV 0xde
88#define ADV7511_REG_ARC_CTRL 0xdf
89#define ADV7511_REG_CEC_I2C_ADDR 0xe1
90#define ADV7511_REG_CEC_CTRL 0xe2
91#define ADV7511_REG_CHIP_ID_HIGH 0xf5
92#define ADV7511_REG_CHIP_ID_LOW 0xf6
93
94#define ADV7511_CSC_ENABLE BIT(7)
95#define ADV7511_CSC_UPDATE_MODE BIT(5)
96
Wolfram Sang29ce4ed2016-01-04 03:33:47 +010097#define ADV7511_INT0_HPD BIT(7)
Lars-Peter Clausen9c8af882012-03-05 16:30:57 +010098#define ADV7511_INT0_VSYNC BIT(5)
99#define ADV7511_INT0_AUDIO_FIFO_FULL BIT(4)
100#define ADV7511_INT0_EDID_READY BIT(2)
101#define ADV7511_INT0_HDCP_AUTHENTICATED BIT(1)
102
103#define ADV7511_INT1_DDC_ERROR BIT(7)
104#define ADV7511_INT1_BKSV BIT(6)
105#define ADV7511_INT1_CEC_TX_READY BIT(5)
106#define ADV7511_INT1_CEC_TX_ARBIT_LOST BIT(4)
107#define ADV7511_INT1_CEC_TX_RETRY_TIMEOUT BIT(3)
108#define ADV7511_INT1_CEC_RX_READY3 BIT(2)
109#define ADV7511_INT1_CEC_RX_READY2 BIT(1)
110#define ADV7511_INT1_CEC_RX_READY1 BIT(0)
111
112#define ADV7511_ARC_CTRL_POWER_DOWN BIT(0)
113
114#define ADV7511_CEC_CTRL_POWER_DOWN BIT(0)
115
116#define ADV7511_POWER_POWER_DOWN BIT(6)
117
118#define ADV7511_HDMI_CFG_MODE_MASK 0x2
119#define ADV7511_HDMI_CFG_MODE_DVI 0x0
120#define ADV7511_HDMI_CFG_MODE_HDMI 0x2
121
122#define ADV7511_AUDIO_SELECT_I2C 0x0
123#define ADV7511_AUDIO_SELECT_SPDIF 0x1
124#define ADV7511_AUDIO_SELECT_DSD 0x2
125#define ADV7511_AUDIO_SELECT_HBR 0x3
126#define ADV7511_AUDIO_SELECT_DST 0x4
127
128#define ADV7511_I2S_SAMPLE_LEN_16 0x2
129#define ADV7511_I2S_SAMPLE_LEN_20 0x3
130#define ADV7511_I2S_SAMPLE_LEN_18 0x4
131#define ADV7511_I2S_SAMPLE_LEN_22 0x5
132#define ADV7511_I2S_SAMPLE_LEN_19 0x8
133#define ADV7511_I2S_SAMPLE_LEN_23 0x9
134#define ADV7511_I2S_SAMPLE_LEN_24 0xb
135#define ADV7511_I2S_SAMPLE_LEN_17 0xc
136#define ADV7511_I2S_SAMPLE_LEN_21 0xd
137
138#define ADV7511_SAMPLE_FREQ_44100 0x0
139#define ADV7511_SAMPLE_FREQ_48000 0x2
140#define ADV7511_SAMPLE_FREQ_32000 0x3
141#define ADV7511_SAMPLE_FREQ_88200 0x8
142#define ADV7511_SAMPLE_FREQ_96000 0xa
143#define ADV7511_SAMPLE_FREQ_176400 0xc
144#define ADV7511_SAMPLE_FREQ_192000 0xe
145
146#define ADV7511_STATUS_POWER_DOWN_POLARITY BIT(7)
147#define ADV7511_STATUS_HPD BIT(6)
148#define ADV7511_STATUS_MONITOR_SENSE BIT(5)
149#define ADV7511_STATUS_I2S_32BIT_MODE BIT(3)
150
151#define ADV7511_PACKET_ENABLE_N_CTS BIT(8+6)
152#define ADV7511_PACKET_ENABLE_AUDIO_SAMPLE BIT(8+5)
153#define ADV7511_PACKET_ENABLE_AVI_INFOFRAME BIT(8+4)
154#define ADV7511_PACKET_ENABLE_AUDIO_INFOFRAME BIT(8+3)
155#define ADV7511_PACKET_ENABLE_GC BIT(7)
156#define ADV7511_PACKET_ENABLE_SPD BIT(6)
157#define ADV7511_PACKET_ENABLE_MPEG BIT(5)
158#define ADV7511_PACKET_ENABLE_ACP BIT(4)
159#define ADV7511_PACKET_ENABLE_ISRC BIT(3)
160#define ADV7511_PACKET_ENABLE_GM BIT(2)
161#define ADV7511_PACKET_ENABLE_SPARE2 BIT(1)
162#define ADV7511_PACKET_ENABLE_SPARE1 BIT(0)
163
Wolfram Sang29ce4ed2016-01-04 03:33:47 +0100164#define ADV7511_REG_POWER2_HPD_SRC_MASK 0xc0
165#define ADV7511_REG_POWER2_HPD_SRC_BOTH 0x00
166#define ADV7511_REG_POWER2_HPD_SRC_HPD 0x40
167#define ADV7511_REG_POWER2_HPD_SRC_CEC 0x80
168#define ADV7511_REG_POWER2_HPD_SRC_NONE 0xc0
Lars-Peter Clausen9c8af882012-03-05 16:30:57 +0100169#define ADV7511_REG_POWER2_TDMS_ENABLE BIT(4)
170#define ADV7511_REG_POWER2_GATE_INPUT_CLK BIT(0)
171
172#define ADV7511_LOW_REFRESH_RATE_NONE 0x0
173#define ADV7511_LOW_REFRESH_RATE_24HZ 0x1
174#define ADV7511_LOW_REFRESH_RATE_25HZ 0x2
175#define ADV7511_LOW_REFRESH_RATE_30HZ 0x3
176
177#define ADV7511_AUDIO_CFG3_LEN_MASK 0x0f
178#define ADV7511_I2C_FREQ_ID_CFG_RATE_MASK 0xf0
179
180#define ADV7511_AUDIO_SOURCE_I2S 0
181#define ADV7511_AUDIO_SOURCE_SPDIF 1
182
183#define ADV7511_I2S_FORMAT_I2S 0
184#define ADV7511_I2S_FORMAT_RIGHT_J 1
185#define ADV7511_I2S_FORMAT_LEFT_J 2
186
187#define ADV7511_PACKET(p, x) ((p) * 0x20 + (x))
188#define ADV7511_PACKET_SDP(x) ADV7511_PACKET(0, x)
189#define ADV7511_PACKET_MPEG(x) ADV7511_PACKET(1, x)
190#define ADV7511_PACKET_ACP(x) ADV7511_PACKET(2, x)
191#define ADV7511_PACKET_ISRC1(x) ADV7511_PACKET(3, x)
192#define ADV7511_PACKET_ISRC2(x) ADV7511_PACKET(4, x)
193#define ADV7511_PACKET_GM(x) ADV7511_PACKET(5, x)
194#define ADV7511_PACKET_SPARE(x) ADV7511_PACKET(6, x)
195
196enum adv7511_input_clock {
197 ADV7511_INPUT_CLOCK_1X,
198 ADV7511_INPUT_CLOCK_2X,
199 ADV7511_INPUT_CLOCK_DDR,
200};
201
202enum adv7511_input_justification {
203 ADV7511_INPUT_JUSTIFICATION_EVENLY = 0,
204 ADV7511_INPUT_JUSTIFICATION_RIGHT = 1,
205 ADV7511_INPUT_JUSTIFICATION_LEFT = 2,
206};
207
208enum adv7511_input_sync_pulse {
209 ADV7511_INPUT_SYNC_PULSE_DE = 0,
210 ADV7511_INPUT_SYNC_PULSE_HSYNC = 1,
211 ADV7511_INPUT_SYNC_PULSE_VSYNC = 2,
212 ADV7511_INPUT_SYNC_PULSE_NONE = 3,
213};
214
215/**
216 * enum adv7511_sync_polarity - Polarity for the input sync signals
217 * @ADV7511_SYNC_POLARITY_PASSTHROUGH: Sync polarity matches that of
218 * the currently configured mode.
219 * @ADV7511_SYNC_POLARITY_LOW: Sync polarity is low
220 * @ADV7511_SYNC_POLARITY_HIGH: Sync polarity is high
221 *
222 * If the polarity is set to either LOW or HIGH the driver will configure the
223 * ADV7511 to internally invert the sync signal if required to match the sync
224 * polarity setting for the currently selected output mode.
225 *
226 * If the polarity is set to PASSTHROUGH, the ADV7511 will route the signal
227 * unchanged. This is used when the upstream graphics core already generates
228 * the sync signals with the correct polarity.
229 */
230enum adv7511_sync_polarity {
231 ADV7511_SYNC_POLARITY_PASSTHROUGH,
232 ADV7511_SYNC_POLARITY_LOW,
233 ADV7511_SYNC_POLARITY_HIGH,
234};
235
236/**
237 * struct adv7511_link_config - Describes adv7511 hardware configuration
238 * @input_color_depth: Number of bits per color component (8, 10 or 12)
239 * @input_colorspace: The input colorspace (RGB, YUV444, YUV422)
240 * @input_clock: The input video clock style (1x, 2x, DDR)
241 * @input_style: The input component arrangement variant
242 * @input_justification: Video input format bit justification
243 * @clock_delay: Clock delay for the input clock (in ps)
244 * @embedded_sync: Video input uses BT.656-style embedded sync
245 * @sync_pulse: Select the sync pulse
246 * @vsync_polarity: vsync input signal configuration
247 * @hsync_polarity: hsync input signal configuration
248 */
249struct adv7511_link_config {
250 unsigned int input_color_depth;
251 enum hdmi_colorspace input_colorspace;
252 enum adv7511_input_clock input_clock;
253 unsigned int input_style;
254 enum adv7511_input_justification input_justification;
255
256 int clock_delay;
257
258 bool embedded_sync;
259 enum adv7511_input_sync_pulse sync_pulse;
260 enum adv7511_sync_polarity vsync_polarity;
261 enum adv7511_sync_polarity hsync_polarity;
262};
263
264/**
265 * enum adv7511_csc_scaling - Scaling factor for the ADV7511 CSC
266 * @ADV7511_CSC_SCALING_1: CSC results are not scaled
267 * @ADV7511_CSC_SCALING_2: CSC results are scaled by a factor of two
268 * @ADV7511_CSC_SCALING_4: CSC results are scalled by a factor of four
269 */
270enum adv7511_csc_scaling {
271 ADV7511_CSC_SCALING_1 = 0,
272 ADV7511_CSC_SCALING_2 = 1,
273 ADV7511_CSC_SCALING_4 = 2,
274};
275
276/**
277 * struct adv7511_video_config - Describes adv7511 hardware configuration
278 * @csc_enable: Whether to enable color space conversion
279 * @csc_scaling_factor: Color space conversion scaling factor
280 * @csc_coefficents: Color space conversion coefficents
281 * @hdmi_mode: Whether to use HDMI or DVI output mode
282 * @avi_infoframe: HDMI infoframe
283 */
284struct adv7511_video_config {
285 bool csc_enable;
286 enum adv7511_csc_scaling csc_scaling_factor;
287 const uint16_t *csc_coefficents;
288
289 bool hdmi_mode;
290 struct hdmi_avi_infoframe avi_infoframe;
291};
292
Archit Taneja2437e7c2016-06-15 16:24:03 +0530293enum adv7511_type {
294 ADV7511,
295 ADV7533,
296};
297
298struct adv7511 {
299 struct i2c_client *i2c_main;
300 struct i2c_client *i2c_edid;
301 struct i2c_client *i2c_cec;
302
303 struct regmap *regmap;
304 struct regmap *regmap_cec;
305 enum drm_connector_status status;
306 bool powered;
307
308 unsigned int f_tmds;
309
310 unsigned int current_edid_segment;
311 uint8_t edid_buf[256];
312 bool edid_read;
313
314 wait_queue_head_t wq;
315 struct drm_bridge bridge;
316 struct drm_connector connector;
317
318 bool embedded_sync;
319 enum adv7511_sync_polarity vsync_polarity;
320 enum adv7511_sync_polarity hsync_polarity;
321 bool rgb;
322
323 struct edid *edid;
324
325 struct gpio_desc *gpio_pd;
326
327 enum adv7511_type type;
328};
329
330#ifdef CONFIG_DRM_I2C_ADV7533
331void adv7533_dsi_power_on(struct adv7511 *adv);
332void adv7533_dsi_power_off(struct adv7511 *adv);
333int adv7533_patch_registers(struct adv7511 *adv);
334void adv7533_uninit_cec(struct adv7511 *adv);
335int adv7533_init_cec(struct adv7511 *adv);
336#else
337static inline void adv7533_dsi_power_on(struct adv7511 *adv)
338{
339}
340
341static inline void adv7533_dsi_power_off(struct adv7511 *adv)
342{
343}
344
345static inline int adv7533_patch_registers(struct adv7511 *adv)
346{
347 return -ENODEV;
348}
349
350static inline void adv7533_uninit_cec(struct adv7511 *adv)
351{
352}
353
354static inline int adv7533_init_cec(struct adv7511 *adv)
355{
356 return -ENODEV;
357}
358#endif
359
Lars-Peter Clausen9c8af882012-03-05 16:30:57 +0100360#endif /* __DRM_I2C_ADV7511_H__ */