1 #ifndef __ROCKCHIP_HDMI_V1_HW_H__
2 #define __ROCKCHIP_HDMI_V1_HW_H__
4 #include <linux/rockchip/iomap.h>
5 #include <linux/delay.h>
18 C0_C2_CHANGE_ENABLE, /* enable c0 c2 change*/
19 C0_C2_CHANGE_DISABLE /* disable c0 c2 change*/
22 /* Auto CSC mode enable */
24 AUTO_CSC_DISABLE, /* disable auto csc*/
25 AUTO_CSC_ENABLE /* enable auto csc*/
29 /* Color Limit Range */
31 COLOR_LIMIT_RANGE_0_255, /* Color Limit Range 0 To 255*/
32 COLOR_LIMIT_RANGE_16_235, /* Color Limit Range 16 To 235*/
34 /* Color Space Convertion Mode */
36 CSC_ITU601_16_235_TO_RGB_0_255_8BIT,/* YCbCr 16-235 input to RGB
37 0-255 output according BT601
38 that is 8bit clolor depth */
39 CSC_ITU601_0_255_TO_RGB_0_255_8BIT, /* YCbCr 0-255 input to RGB
40 0-255 output according BT601
41 that is 8bit clolor depth */
42 CSC_ITU709_16_235_TO_RGB_0_255_8BIT,/* YCbCr 16-235 input to RGB
43 0-255 output according BT709
44 that is 8bit clolor depth */
45 CSC_RGB_0_255_TO_ITU601_16_235_8BIT,/* RGB 0-255 input to YCbCr
46 16-235 output according BT601
47 that is 8bit clolor depth */
48 CSC_RGB_0_255_TO_ITU709_16_235_8BIT,/* RGB 0-255 input to YCbCr 16-235
49 output accroding BT709 that is
51 CSC_RGB_0_255_TO_RGB_16_235_8BIT, /* RGB 0-255 input to RGB 16-235
52 output that is 8bit clolor depth
57 #define AUTO_DEFINE_CSC
58 #ifdef RK616_USE_MCLK_12M
59 #define HDMI_SYS_FREG_CLK 12000000
61 #define HDMI_SYS_FREG_CLK 11289600
64 #define HDMI_SCL_RATE (100*1000)
65 #define DDC_BUS_FREQ_L 0x4b
66 #define DDC_BUS_FREQ_H 0x4c
69 #define m_RST_ANALOG (1 << 6)
70 #define v_RST_ANALOG (0 << 6)
71 #define v_NOT_RST_ANALOG (1 << 6)
73 #define m_RST_DIGITAL (1 << 5)
74 #define v_RST_DIGITAL (0 << 5)
75 #define v_NOT_RST_DIGITAL (1 << 5)
77 #define m_REG_CLK_INV (1 << 4)
78 #define v_REG_CLK_NOT_INV (0 << 4)
79 #define v_REG_CLK_INV (1 << 4)
80 #define m_VCLK_INV (1 << 3)
81 #define v_VCLK_NOT_INV (0 << 3)
82 #define v_VCLK_INV (1 << 3)
83 #define m_REG_CLK_SOURCE (1 << 2)
84 #define v_REG_CLK_SOURCE_TMDS (0 << 2)
85 #define v_REG_CLK_SOURCE_SYS (1 << 2)
86 #define m_POWER (1 << 1)
87 #define v_PWR_ON (0 << 1)
88 #define v_PWR_OFF (1 << 1)
89 #define m_INT_POL (1 << 0)
90 #define v_INT_POL_HIGH 1
91 #define v_INT_POL_LOW 0
93 #define VIDEO_CONTRL1 0x01
94 #define m_VIDEO_INPUT_FORMAT (7 << 1)
95 #define m_DE_SOURCE (1 << 0)
97 VIDEO_INPUT_SDR_RGB444 = 0,
98 VIDEO_INPUT_DDR_RGB444 = 5,
99 VIDEO_INPUT_DDR_YCBCR422 = 6
101 #define v_VIDEO_INPUT_FORMAT(n) (n << 1)
102 #define v_DE_EXTERNAL 1
103 #define v_DE_INTERANL 0
105 #define VIDEO_CONTRL2 0x02
106 #define m_VIDEO_OUTPUT_COLOR (3 << 6)
107 #define m_VIDEO_INPUT_BITS (3 << 4)
108 #define m_VIDEO_INPUT_CSP (1 << 0)
109 #define v_VIDEO_OUTPUT_COLOR(n) (((n)&0x3) << 6)
110 #define v_VIDEO_INPUT_BITS(n) (n << 4)
111 #define v_VIDEO_INPUT_CSP(n) (n << 0)
114 VIDEO_INPUT_12BITS = 0,
119 #define VIDEO_CONTRL 0x03
120 #define m_VIDEO_AUTO_CSC (1 << 7)
121 #define v_VIDEO_AUTO_CSC(n) (n << 7)
122 #define m_VIDEO_C0_C2_SWAP (1 << 0)
123 #define v_VIDEO_C0_C2_SWAP(n) (n << 0)
126 #define VIDEO_CONTRL3 0x04
127 #define m_COLOR_DEPTH_NOT_INDICATED (1 << 4)
128 #define m_SOF (1 << 3)
129 #define m_COLOR_RANGE (1 << 2)
130 #define m_CSC (1 << 0)
131 #define v_COLOR_DEPTH_NOT_INDICATED(n) ((n) << 4) /*1: Force GCP CD[3:0] zero
132 0: GCP CD[3:0] according
134 #define v_SOF_ENABLE (0 << 3)
135 #define v_SOF_DISABLE (1 << 3)
136 #define v_COLOR_RANGE_FULL (1 << 2)
137 #define v_COLOR_RANGE_LIMITED (0 << 2)
138 #define v_CSC_ENABLE 1
139 #define v_CSC_DISABLE 0
142 #define m_AVMUTE_CLEAR (1 << 7)
143 #define m_AVMUTE_ENABLE (1 << 6)
144 #define m_AUDIO_PD (1 << 2)
145 #define m_AUDIO_MUTE (1 << 1)
146 #define m_VIDEO_BLACK (1 << 0)
147 #define v_AVMUTE_CLEAR(n) (n << 7)
148 #define v_AVMUTE_ENABLE(n) (n << 6)
149 #define v_AUDIO_PD(n) (n << 2)
150 #define v_AUDIO_MUTE(n) (n << 1)
151 #define v_VIDEO_MUTE(n) (n << 0)
153 #define VIDEO_TIMING_CTL 0x08
154 #define v_HSYNC_POLARITY(n) (n << 3)
155 #define v_VSYNC_POLARITY(n) (n << 2)
156 #define v_INETLACE(n) (n << 1)
157 #define v_EXTERANL_VIDEO(n) (n << 0)
159 #define VIDEO_EXT_HTOTAL_L 0x09
160 #define VIDEO_EXT_HTOTAL_H 0x0a
161 #define VIDEO_EXT_HBLANK_L 0x0b
162 #define VIDEO_EXT_HBLANK_H 0x0c
163 #define VIDEO_EXT_HDELAY_L 0x0d
164 #define VIDEO_EXT_HDELAY_H 0x0e
165 #define VIDEO_EXT_HDURATION_L 0x0f
166 #define VIDEO_EXT_HDURATION_H 0x10
167 #define VIDEO_EXT_VTOTAL_L 0x11
168 #define VIDEO_EXT_VTOTAL_H 0x12
169 #define VIDEO_EXT_VBLANK 0x13
170 #define VIDEO_EXT_VDELAY 0x14
171 #define VIDEO_EXT_VDURATION 0x15
173 #define VIDEO_CSC_COEF 0x18
176 #define AUDIO_CTRL1 0x35
178 CTS_SOURCE_INTERNAL = 0,
181 #define v_CTS_SOURCE(n) (n << 7)
183 DOWNSAMPLE_DISABLE = 0,
187 #define v_DOWN_SAMPLE(n) (n << 5)
189 AUDIO_SOURCE_IIS = 0,
192 #define v_AUDIO_SOURCE(n) (n << 3)
193 #define v_MCLK_ENABLE(n) (n << 2)
200 #define v_MCLK_RATIO(n) (n)
202 #define AUDIO_SAMPLE_RATE 0x37
213 #define AUDIO_I2S_MODE 0x38
218 I2S_CHANNEL_7_8 = 0xf
220 #define v_I2S_CHANNEL(n) ((n) << 2)
226 #define v_I2S_MODE(n) (n)
228 #define AUDIO_I2S_MAP 0x39
229 #define AUDIO_I2S_SWAPS_SPDIF 0x3a
230 #define v_SPIDF_FREQ(n) (n)
233 #define N_441K 0x1880
234 #define N_882K 0x3100
235 #define N_1764K 0x6200
238 #define N_192K 0x6000
240 #define AUDIO_CHANNEL_STATUS 0x3e
241 #define m_AUDIO_STATUS_NLPCM (1 << 7)
242 #define m_AUDIO_STATUS_USE (1 << 6)
243 #define m_AUDIO_STATUS_COPYRIGHT (1 << 5)
244 #define m_AUDIO_STATUS_ADDITION (3 << 2)
245 #define m_AUDIO_STATUS_CLK_ACCURACY (2 << 0)
247 #define v_AUDIO_STATUS_NLPCM(n) ((n & 1) << 7)
248 #define AUDIO_N_H 0x3f
249 #define AUDIO_N_M 0x40
250 #define AUDIO_N_L 0x41
252 #define AUDIO_CTS_H 0x45
253 #define AUDIO_CTS_M 0x46
254 #define AUDIO_CTS_L 0x47
256 #define DDC_CLK_L 0x4b
257 #define DDC_CLK_H 0x4c
259 #define EDID_SEGMENT_POINTER 0x4d
260 #define EDID_WORD_ADDR 0x4e
261 #define EDID_FIFO_OFFSET 0x4f
262 #define EDID_FIFO_ADDR 0x50
265 #define PACKET_SEND_MANUAL 0x9c
266 #define PACKET_SEND_AUTO 0x9d
267 #define m_PACKET_GCP_EN (1 << 7)
268 #define m_PACKET_MSI_EN (1 << 6) /*MPEG Source InfoFrame*/
269 #define m_PACKET_SDI_EN (1 << 5) /*Source product descriptor*/
270 #define m_PACKET_VSI_EN (1 << 4) /*HDMI Vendor Specific
272 #define v_PACKET_GCP_EN(n) ((n & 1) << 7)
273 #define v_PACKET_MSI_EN(n) ((n & 1) << 6)
274 #define v_PACKET_SDI_EN(n) ((n & 1) << 5)
275 #define v_PACKET_VSI_EN(n) ((n & 1) << 4)
277 /* CONTROL_PACKET_BUF_INDEX */
278 #define CONTROL_PACKET_BUF_INDEX 0x9f
280 INFOFRAME_VSI = 0x05,
281 INFOFRAME_AVI = 0x06,
282 INFOFRAME_AAI = 0x08,
284 #define CONTROL_PACKET_ADDR 0xa0
285 #define SIZE_VSI_INFOFRAME 0x0A /* 10 bytes */
286 #define SIZE_AVI_INFOFRAME 0x11 /* 14 bytes */
287 #define SIZE_AUDIO_INFOFRAME 0x0F /* 15 bytes */
289 AVI_COLOR_MODE_RGB = 0,
290 AVI_COLOR_MODE_YCBCR422,
291 AVI_COLOR_MODE_YCBCR444
294 AVI_COLORIMETRY_NO_DATA = 0,
295 AVI_COLORIMETRY_SMPTE_170M,
296 AVI_COLORIMETRY_ITU709,
297 AVI_COLORIMETRY_EXTENDED
300 AVI_CODED_FRAME_ASPECT_NO_DATA,
301 AVI_CODED_FRAME_ASPECT_4_3,
302 AVI_CODED_FRAME_ASPECT_16_9
305 ACTIVE_ASPECT_RATE_SAME_AS_CODED_FRAME = 0x08,
306 ACTIVE_ASPECT_RATE_4_3,
307 ACTIVE_ASPECT_RATE_16_9,
308 ACTIVE_ASPECT_RATE_14_9
311 #define HDCP_CTRL 0x52
312 #define m_HDMI_DVI (1 << 1)
313 #define v_HDMI_DVI(n) (n << 1)
315 #define INTERRUPT_MASK1 0xc0
316 #define INTERRUPT_STATUS1 0xc1
317 #define m_INT_ACTIVE_VSYNC (1 << 5)
318 #define m_INT_EDID_READY (1 << 2)
320 #define INTERRUPT_MASK2 0xc2
321 #define INTERRUPT_STATUS2 0xc3
322 #define m_INT_HDCP_ERR (1 << 7)
323 #define m_INT_BKSV_FLAG (1 << 6)
324 #define m_INT_HDCP_OK (1 << 4)
326 #define HDMI_STATUS 0xc8
327 #define m_HOTPLUG (1 << 7)
328 #define m_MASK_INT_HOTPLUG (1 << 5)
329 #define m_INT_HOTPLUG (1 << 1)
330 #define v_MASK_INT_HOTPLUG(n) ((n & 0x1) << 5)
332 #define HDMI_COLORBAR 0xc9
334 #define PHY_SYNC 0xce /* sync phy parameter */
335 #define PHY_SYS_CTL 0xe0
336 #define m_TMDS_CLK_SOURCE (1 << 5)
337 #define v_TMDS_FROM_PLL (0 << 5)
338 #define v_TMDS_FROM_GEN (1 << 5)
339 #define m_PHASE_CLK (1 << 4)
340 #define v_DEFAULT_PHASE (0 << 4)
341 #define v_SYNC_PHASE (1 << 4)
342 #define m_TMDS_CURRENT_PWR (1 << 3)
343 #define v_TURN_ON_CURRENT (0 << 3)
344 #define v_CAT_OFF_CURRENT (1 << 3)
345 #define m_BANDGAP_PWR (1 << 2)
346 #define v_BANDGAP_PWR_UP (0 << 2)
347 #define v_BANDGAP_PWR_DOWN (1 << 2)
348 #define m_PLL_PWR (1 << 1)
349 #define v_PLL_PWR_UP (0 << 1)
350 #define v_PLL_PWR_DOWN (1 << 1)
351 #define m_TMDS_CHG_PWR (1 << 0)
352 #define v_TMDS_CHG_PWR_UP (0 << 0)
353 #define v_TMDS_CHG_PWR_DOWN (1 << 0)
355 #define PHY_CHG_PWR 0xe1
356 #define v_CLK_CHG_PWR(n) ((n & 1) << 3)
357 #define v_DATA_CHG_PWR(n) ((n & 7) << 0)
359 #define PHY_DRIVER 0xe2
360 #define v_CLK_MAIN_DRIVER(n) (n << 4)
361 #define v_DATA_MAIN_DRIVER(n) (n << 0)
363 #define PHY_PRE_EMPHASIS 0xe3
364 #define v_PRE_EMPHASIS(n) ((n & 7) << 4)
365 #define v_CLK_PRE_DRIVER(n) ((n & 3) << 2)
366 #define v_DATA_PRE_DRIVER(n) ((n & 3) << 0)
368 #define PHY_FEEDBACK_DIV_RATIO_LOW 0xe7
369 #define v_FEEDBACK_DIV_LOW(n) (n & 0xff)
370 #define PHY_FEEDBACK_DIV_RATIO_HIGH 0xe8
371 #define v_FEEDBACK_DIV_HIGH(n) (n & 1)
373 #define PHY_PRE_DIV_RATIO 0xed
374 #define v_PRE_DIV_RATIO(n) (n & 0x1f)
377 /*-----START----- HDMI CEC CTRL------START------*/
378 #define CEC_CTRL 0xd0
379 #define m_ADJUST_FOR_HISENSE (1 << 6)
380 #define m_REJECT_RX_BROADCAST (1 << 5)
381 #define m_BUSFREETIME_ENABLE (1 << 2)
382 #define m_REJECT_RX (1 << 1)
383 #define m_START_TX (1 << 0)
385 #define CEC_DATA 0xd1
386 #define CEC_TX_OFFSET 0xd2
387 #define CEC_RX_OFFSET 0xd3
388 #define CEC_CLK_H 0xd4
389 #define CEC_CLK_L 0xd5
390 #define CEC_TX_LENGTH 0xd6
391 #define CEC_RX_LENGTH 0xd7
392 #define CEC_TX_INT_MASK 0xd8
393 #define m_TX_DONE (1 << 3)
394 #define m_TX_NOACK (1 << 2)
395 #define m_TX_BROADCAST_REJ (1 << 1)
396 #define m_TX_BUSNOTFREE (1 << 0)
398 #define CEC_RX_INT_MASK 0xd9
399 #define m_RX_LA_ERR (1 << 4)
400 #define m_RX_GLITCH (1 << 3)
401 #define m_RX_DONE (1 << 0)
403 #define CEC_TX_INT 0xda
404 #define CEC_RX_INT 0xdb
405 #define CEC_BUSFREETIME_L 0xdc
406 #define CEC_BUSFREETIME_H 0xdd
407 #define CEC_LOGICADDR 0xde
408 /*------END------ HDMI CEC CTRL------END-------*/
411 static inline int hdmi_readl(struct hdmi_dev *hdmi_dev,
417 *val = readl_relaxed(hdmi_dev->regbase + (offset) * 0x04);
421 static inline int hdmi_writel(struct hdmi_dev *hdmi_dev,
427 writel_relaxed(val, hdmi_dev->regbase + (offset) * 0x04);
431 static inline int hdmi_msk_reg(struct hdmi_dev *hdmi_dev,
432 u16 offset, u32 msk, u32 val)
437 temp = readl_relaxed(hdmi_dev->regbase +
438 (offset) * 0x04) & (0xFF - (msk));
439 writel_relaxed(temp | ((val) & (msk)),
440 hdmi_dev->regbase + (offset) * 0x04);
443 static inline void rockchip_hdmiv1_reset_pclk(void)
445 writel_relaxed(0x00010001, RK_CRU_VIRT + 0x128);
447 writel_relaxed(0x00010000, RK_CRU_VIRT + 0x128);
452 void rockchip_hdmiv1_dev_init_ops(struct hdmi_ops *ops);
453 int rockchip_hdmiv1_initial(struct hdmi *hdmi);
454 void rockchip_hdmiv1_irq(struct hdmi *hdmi);
455 void rockchip_hdmiv1_cec_init(struct hdmi *hdmi);
456 void rockchip_hdmiv1_cec_isr(struct hdmi_dev *hdmi_dev);