video: rockchip: hdmi: sync to develop-3.10
[firefly-linux-kernel-4.4.55.git] / drivers / video / rockchip / hdmi / rockchip-hdmiv1 / rockchip_hdmiv1_hw.h
1 #ifndef __ROCKCHIP_HDMI_V1_HW_H__
2 #define __ROCKCHIP_HDMI_V1_HW_H__
3
4 #include <linux/rockchip/iomap.h>
5 #include <linux/delay.h>
6
7 enum PWR_MODE {
8         NORMAL,
9         LOWER_PWR,
10 };
11 enum {
12         OUTPUT_DVI = 0,
13         OUTPUT_HDMI
14 };
15
16 /* C0 C2 Change */
17 enum {
18         C0_C2_CHANGE_ENABLE,    /* enable c0 c2 change*/
19         C0_C2_CHANGE_DISABLE    /* disable c0 c2 change*/
20 };
21
22 /* Auto CSC mode enable */
23 enum {
24         AUTO_CSC_DISABLE,       /* disable auto csc*/
25         AUTO_CSC_ENABLE /* enable auto csc*/
26 };
27
28
29 /* Color Limit Range */
30 enum {
31         COLOR_LIMIT_RANGE_0_255,        /* Color Limit Range 0 To 255*/
32         COLOR_LIMIT_RANGE_16_235,       /* Color Limit Range 16 To 235*/
33 };
34 /* Color Space Convertion Mode */
35 enum {
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                                              */
40         CSC_ITU601_0_255_TO_RGB_0_255_8BIT, /* YCbCr 0-255 input to RGB
41                                              * 0-255 output according BT601
42                                              * that is 8bit clolor depth
43                                              */
44         CSC_ITU709_16_235_TO_RGB_0_255_8BIT,/* YCbCr 16-235 input to RGB
45                                              * 0-255 output according BT709
46                                              * that is 8bit clolor depth
47                                              */
48         CSC_RGB_0_255_TO_ITU601_16_235_8BIT,/* RGB 0-255 input to YCbCr
49                                              * 16-235 output according BT601
50                                              * that is 8bit clolor depth
51                                              */
52         CSC_RGB_0_255_TO_ITU709_16_235_8BIT,/* RGB 0-255 input to YCbCr 16-235
53                                              * output accroding BT709 that is
54                                              * 8bit clolor depth
55                                              */
56         CSC_RGB_0_255_TO_RGB_16_235_8BIT,   /* RGB 0-255 input to RGB 16-235
57                                              * output that is 8bit clolor depth
58                                              */
59 };
60
61
62 #define AUTO_DEFINE_CSC
63 #ifdef RK616_USE_MCLK_12M
64 #define HDMI_SYS_FREG_CLK        12000000
65 #else
66 #define HDMI_SYS_FREG_CLK        11289600
67 #endif
68
69 #define HDMI_SCL_RATE            (100*1000)
70 #define DDC_BUS_FREQ_L                  0x4b
71 #define DDC_BUS_FREQ_H                  0x4c
72
73 #define SYS_CTRL                        0x00
74 #define m_RST_ANALOG            (1 << 6)
75 #define v_RST_ANALOG            (0 << 6)
76 #define v_NOT_RST_ANALOG        (1 << 6)
77
78 #define m_RST_DIGITAL           (1 << 5)
79 #define v_RST_DIGITAL           (0 << 5)
80 #define v_NOT_RST_DIGITAL       (1 << 5)
81
82 #define m_REG_CLK_INV           (1 << 4)
83 #define v_REG_CLK_NOT_INV       (0 << 4)
84 #define v_REG_CLK_INV           (1 << 4)
85 #define m_VCLK_INV              (1 << 3)
86 #define v_VCLK_NOT_INV          (0 << 3)
87 #define v_VCLK_INV              (1 << 3)
88 #define m_REG_CLK_SOURCE        (1 << 2)
89 #define v_REG_CLK_SOURCE_TMDS   (0 << 2)
90 #define v_REG_CLK_SOURCE_SYS    (1 << 2)
91 #define m_POWER                 (1 << 1)
92 #define v_PWR_ON                (0 << 1)
93 #define v_PWR_OFF               (1 << 1)
94 #define m_INT_POL               (1 << 0)
95 #define v_INT_POL_HIGH          1
96 #define v_INT_POL_LOW           0
97
98 #define VIDEO_CONTRL1                   0x01
99 #define m_VIDEO_INPUT_FORMAT    (7 << 1)
100 #define m_DE_SOURCE             (1 << 0)
101 enum {
102         VIDEO_INPUT_SDR_RGB444 = 0,
103         VIDEO_INPUT_DDR_RGB444 = 5,
104         VIDEO_INPUT_DDR_YCBCR422 = 6
105 };
106 #define v_VIDEO_INPUT_FORMAT(n) (n << 1)
107 #define v_DE_EXTERNAL           1
108 #define v_DE_INTERANL           0
109
110 #define VIDEO_CONTRL2                   0x02
111 #define m_VIDEO_OUTPUT_COLOR    (3 << 6)
112 #define m_VIDEO_INPUT_BITS      (3 << 4)
113 #define m_VIDEO_INPUT_CSP       (1 << 0)
114 #define v_VIDEO_OUTPUT_COLOR(n) (((n)&0x3) << 6)
115 #define v_VIDEO_INPUT_BITS(n)   (n << 4)
116 #define v_VIDEO_INPUT_CSP(n)    (n << 0)
117
118 enum {
119         VIDEO_INPUT_12BITS = 0,
120         VIDEO_INPUT_10BITS,
121         VIDEO_INPUT_REVERT,
122         VIDEO_INPUT_8BITS
123 };
124 #define VIDEO_CONTRL                    0x03
125 #define m_VIDEO_AUTO_CSC                (1 << 7)
126 #define v_VIDEO_AUTO_CSC(n)             (n << 7)
127 #define m_VIDEO_C0_C2_SWAP              (1 << 0)
128 #define v_VIDEO_C0_C2_SWAP(n)           (n << 0)
129
130
131 #define VIDEO_CONTRL3                   0x04
132 #define m_COLOR_DEPTH_NOT_INDICATED (1 << 4)
133 #define m_SOF                   (1 << 3)
134 #define m_COLOR_RANGE           (1 << 2)
135 #define m_CSC                   (1 << 0)
136 #define v_COLOR_DEPTH_NOT_INDICATED(n) ((n) << 4) /* 1: Force GCP CD[3:0] zero
137                                                    * 0: GCP CD[3:0] according
138                                                    *    color depth
139                                                    */
140 #define v_SOF_ENABLE            (0 << 3)
141 #define v_SOF_DISABLE           (1 << 3)
142 #define v_COLOR_RANGE_FULL      (1 << 2)
143 #define v_COLOR_RANGE_LIMITED   (0 << 2)
144 #define v_CSC_ENABLE            1
145 #define v_CSC_DISABLE           0
146
147 #define AV_MUTE                         0x05
148 #define m_AVMUTE_CLEAR          (1 << 7)
149 #define m_AVMUTE_ENABLE         (1 << 6)
150 #define m_AUDIO_PD              (1 << 2)
151 #define m_AUDIO_MUTE            (1 << 1)
152 #define m_VIDEO_BLACK           (1 << 0)
153 #define v_AVMUTE_CLEAR(n)       (n << 7)
154 #define v_AVMUTE_ENABLE(n)      (n << 6)
155 #define v_AUDIO_PD(n)           (n << 2)
156 #define v_AUDIO_MUTE(n)         (n << 1)
157 #define v_VIDEO_MUTE(n)         (n << 0)
158
159 #define VIDEO_TIMING_CTL                0x08
160 #define v_HSYNC_POLARITY(n)     (n << 3)
161 #define v_VSYNC_POLARITY(n)     (n << 2)
162 #define v_INETLACE(n)           (n << 1)
163 #define v_EXTERANL_VIDEO(n)     (n << 0)
164
165 #define VIDEO_EXT_HTOTAL_L              0x09
166 #define VIDEO_EXT_HTOTAL_H              0x0a
167 #define VIDEO_EXT_HBLANK_L              0x0b
168 #define VIDEO_EXT_HBLANK_H              0x0c
169 #define VIDEO_EXT_HDELAY_L              0x0d
170 #define VIDEO_EXT_HDELAY_H              0x0e
171 #define VIDEO_EXT_HDURATION_L           0x0f
172 #define VIDEO_EXT_HDURATION_H           0x10
173 #define VIDEO_EXT_VTOTAL_L              0x11
174 #define VIDEO_EXT_VTOTAL_H              0x12
175 #define VIDEO_EXT_VBLANK                0x13
176 #define VIDEO_EXT_VDELAY                0x14
177 #define VIDEO_EXT_VDURATION             0x15
178
179 #define VIDEO_CSC_COEF                  0x18
180
181
182 #define AUDIO_CTRL1                     0x35
183 enum {
184         CTS_SOURCE_INTERNAL = 0,
185         CTS_SOURCE_EXTERNAL
186 };
187 #define v_CTS_SOURCE(n)         (n << 7)
188 enum {
189         DOWNSAMPLE_DISABLE = 0,
190         DOWNSAMPLE_1_2,
191         DOWNSAMPLE_1_4
192 };
193 #define v_DOWN_SAMPLE(n)        (n << 5)
194 enum {
195         AUDIO_SOURCE_IIS = 0,
196         AUDIO_SOURCE_SPDIF
197 };
198 #define v_AUDIO_SOURCE(n)       (n << 3)
199 #define v_MCLK_ENABLE(n)        (n << 2)
200 enum {
201         MCLK_128FS = 0,
202         MCLK_256FS,
203         MCLK_384FS,
204         MCLK_512FS
205 };
206 #define v_MCLK_RATIO(n)         (n)
207
208 #define AUDIO_SAMPLE_RATE               0x37
209 enum {
210         AUDIO_32K = 0x3,
211         AUDIO_441K = 0x0,
212         AUDIO_48K = 0x2,
213         AUDIO_882K = 0x8,
214         AUDIO_96K = 0xa,
215         AUDIO_1764K = 0xc,
216         AUDIO_192K = 0xe,
217 };
218
219 #define AUDIO_I2S_MODE                  0x38
220 enum {
221         I2S_CHANNEL_1_2 = 1,
222         I2S_CHANNEL_3_4 = 3,
223         I2S_CHANNEL_5_6 = 7,
224         I2S_CHANNEL_7_8 = 0xf
225 };
226 #define v_I2S_CHANNEL(n)        ((n) << 2)
227 enum {
228         I2S_STANDARD = 0,
229         I2S_LEFT_JUSTIFIED,
230         I2S_RIGHT_JUSTIFIED
231 };
232 #define v_I2S_MODE(n)           (n)
233
234 #define AUDIO_I2S_MAP                   0x39
235 #define AUDIO_I2S_SWAPS_SPDIF           0x3a
236 #define v_SPIDF_FREQ(n)         (n)
237
238 #define N_32K           0x1000
239 #define N_441K          0x1880
240 #define N_882K          0x3100
241 #define N_1764K         0x6200
242 #define N_48K           0x1800
243 #define N_96K           0x3000
244 #define N_192K          0x6000
245
246 #define AUDIO_CHANNEL_STATUS            0x3e
247         #define m_AUDIO_STATUS_NLPCM            (1 << 7)
248         #define m_AUDIO_STATUS_USE              (1 << 6)
249         #define m_AUDIO_STATUS_COPYRIGHT        (1 << 5)
250         #define m_AUDIO_STATUS_ADDITION         (3 << 2)
251         #define m_AUDIO_STATUS_CLK_ACCURACY     (2 << 0)
252
253         #define v_AUDIO_STATUS_NLPCM(n)         ((n & 1) << 7)
254 #define AUDIO_N_H                       0x3f
255 #define AUDIO_N_M                       0x40
256 #define AUDIO_N_L                       0x41
257
258 #define AUDIO_CTS_H                     0x45
259 #define AUDIO_CTS_M                     0x46
260 #define AUDIO_CTS_L                     0x47
261
262 #define DDC_CLK_L                       0x4b
263 #define DDC_CLK_H                       0x4c
264
265 #define EDID_SEGMENT_POINTER            0x4d
266 #define EDID_WORD_ADDR                  0x4e
267 #define EDID_FIFO_OFFSET                0x4f
268 #define EDID_FIFO_ADDR                  0x50
269
270
271 #define PACKET_SEND_MANUAL              0x9c
272 #define PACKET_SEND_AUTO                0x9d
273         #define m_PACKET_GCP_EN         (1 << 7)
274         #define m_PACKET_MSI_EN         (1 << 6) /* MPEG Source InfoFrame */
275         #define m_PACKET_SDI_EN         (1 << 5) /* Source product descriptor */
276         #define m_PACKET_VSI_EN         (1 << 4) /* HDMI Vendor Specific
277                                                   * InfoFrame
278                                                   */
279         #define v_PACKET_GCP_EN(n)      ((n & 1) << 7)
280         #define v_PACKET_MSI_EN(n)      ((n & 1) << 6)
281         #define v_PACKET_SDI_EN(n)      ((n & 1) << 5)
282         #define v_PACKET_VSI_EN(n)      ((n & 1) << 4)
283
284 /* CONTROL_PACKET_BUF_INDEX */
285 #define CONTROL_PACKET_BUF_INDEX        0x9f
286 enum {
287         INFOFRAME_VSI = 0x05,
288         INFOFRAME_AVI = 0x06,
289         INFOFRAME_AAI = 0x08,
290 };
291 #define CONTROL_PACKET_ADDR             0xa0
292 #define SIZE_VSI_INFOFRAME              0x0A    /* 10 bytes */
293 #define SIZE_AVI_INFOFRAME              0x11    /* 14 bytes */
294 #define SIZE_AUDIO_INFOFRAME            0x0F    /* 15 bytes */
295 enum {
296         AVI_COLOR_MODE_RGB = 0,
297         AVI_COLOR_MODE_YCBCR422,
298         AVI_COLOR_MODE_YCBCR444
299 };
300 enum {
301         AVI_COLORIMETRY_NO_DATA = 0,
302         AVI_COLORIMETRY_SMPTE_170M,
303         AVI_COLORIMETRY_ITU709,
304         AVI_COLORIMETRY_EXTENDED
305 };
306 enum {
307         AVI_CODED_FRAME_ASPECT_NO_DATA,
308         AVI_CODED_FRAME_ASPECT_4_3,
309         AVI_CODED_FRAME_ASPECT_16_9
310 };
311 enum {
312         ACTIVE_ASPECT_RATE_SAME_AS_CODED_FRAME = 0x08,
313         ACTIVE_ASPECT_RATE_4_3,
314         ACTIVE_ASPECT_RATE_16_9,
315         ACTIVE_ASPECT_RATE_14_9
316 };
317
318 #define HDCP_CTRL                       0x52
319 #define m_HDMI_DVI              (1 << 1)
320 #define v_HDMI_DVI(n)           (n << 1)
321
322 #define INTERRUPT_MASK1                 0xc0
323 #define INTERRUPT_STATUS1               0xc1
324 #define m_INT_ACTIVE_VSYNC      (1 << 5)
325 #define m_INT_EDID_READY        (1 << 2)
326
327 #define INTERRUPT_MASK2                 0xc2
328 #define INTERRUPT_STATUS2               0xc3
329 #define m_INT_HDCP_ERR          (1 << 7)
330 #define m_INT_BKSV_FLAG         (1 << 6)
331 #define m_INT_HDCP_OK           (1 << 4)
332
333 #define HDMI_STATUS                     0xc8
334         #define m_HOTPLUG       (1 << 7)
335         #define m_MASK_INT_HOTPLUG      (1 << 5)
336         #define m_INT_HOTPLUG           (1 << 1)
337         #define v_MASK_INT_HOTPLUG(n)   ((n & 0x1) << 5)
338
339 #define HDMI_COLORBAR                   0xc9
340
341 #define PHY_SYNC                        0xce    /* sync phy parameter */
342 #define PHY_SYS_CTL                     0xe0
343 #define m_TMDS_CLK_SOURCE       (1 << 5)
344 #define v_TMDS_FROM_PLL         (0 << 5)
345 #define v_TMDS_FROM_GEN         (1 << 5)
346 #define m_PHASE_CLK             (1 << 4)
347 #define v_DEFAULT_PHASE         (0 << 4)
348 #define v_SYNC_PHASE            (1 << 4)
349 #define m_TMDS_CURRENT_PWR      (1 << 3)
350 #define v_TURN_ON_CURRENT       (0 << 3)
351 #define v_CAT_OFF_CURRENT       (1 << 3)
352 #define m_BANDGAP_PWR           (1 << 2)
353 #define v_BANDGAP_PWR_UP        (0 << 2)
354 #define v_BANDGAP_PWR_DOWN      (1 << 2)
355 #define m_PLL_PWR               (1 << 1)
356 #define v_PLL_PWR_UP            (0 << 1)
357 #define v_PLL_PWR_DOWN          (1 << 1)
358 #define m_TMDS_CHG_PWR          (1 << 0)
359 #define v_TMDS_CHG_PWR_UP       (0 << 0)
360 #define v_TMDS_CHG_PWR_DOWN     (1 << 0)
361
362 #define PHY_CHG_PWR                     0xe1
363 #define v_CLK_CHG_PWR(n)        ((n & 1) << 3)
364 #define v_DATA_CHG_PWR(n)       ((n & 7) << 0)
365
366 #define PHY_DRIVER                      0xe2
367 #define v_CLK_MAIN_DRIVER(n)    (n << 4)
368 #define v_DATA_MAIN_DRIVER(n)   (n << 0)
369
370 #define PHY_PRE_EMPHASIS                0xe3
371 #define v_PRE_EMPHASIS(n)       ((n & 7) << 4)
372 #define v_CLK_PRE_DRIVER(n)     ((n & 3) << 2)
373 #define v_DATA_PRE_DRIVER(n)    ((n & 3) << 0)
374
375 #define PHY_FEEDBACK_DIV_RATIO_LOW      0xe7
376 #define v_FEEDBACK_DIV_LOW(n)   (n & 0xff)
377 #define PHY_FEEDBACK_DIV_RATIO_HIGH     0xe8
378 #define v_FEEDBACK_DIV_HIGH(n)  (n & 1)
379
380 #define PHY_PRE_DIV_RATIO               0xed
381 #define v_PRE_DIV_RATIO(n)      (n & 0x1f)
382
383
384 /*-----START----- HDMI CEC CTRL------START------*/
385 #define CEC_CTRL                0xd0
386         #define m_ADJUST_FOR_HISENSE    (1 << 6)
387         #define m_REJECT_RX_BROADCAST   (1 << 5)
388         #define m_BUSFREETIME_ENABLE    (1 << 2)
389         #define m_REJECT_RX                             (1 << 1)
390         #define m_START_TX                              (1 << 0)
391
392 #define CEC_DATA                0xd1
393 #define CEC_TX_OFFSET   0xd2
394 #define CEC_RX_OFFSET   0xd3
395 #define CEC_CLK_H               0xd4
396 #define CEC_CLK_L               0xd5
397 #define CEC_TX_LENGTH   0xd6
398 #define CEC_RX_LENGTH   0xd7
399 #define CEC_TX_INT_MASK 0xd8
400         #define m_TX_DONE                       (1 << 3)
401         #define m_TX_NOACK                      (1 << 2)
402         #define m_TX_BROADCAST_REJ      (1 << 1)
403         #define m_TX_BUSNOTFREE         (1 << 0)
404
405 #define CEC_RX_INT_MASK 0xd9
406         #define m_RX_LA_ERR                     (1 << 4)
407         #define m_RX_GLITCH                     (1 << 3)
408         #define m_RX_DONE                       (1 << 0)
409
410 #define CEC_TX_INT              0xda
411 #define CEC_RX_INT              0xdb
412 #define CEC_BUSFREETIME_L       0xdc
413 #define CEC_BUSFREETIME_H       0xdd
414 #define CEC_LOGICADDR           0xde
415 /*------END------ HDMI CEC CTRL------END-------*/
416
417
418 static inline int hdmi_readl(struct hdmi_dev *hdmi_dev,
419                              u16 offset,
420                              u32 *val)
421 {
422         int ret = 0;
423
424         *val = readl_relaxed(hdmi_dev->regbase + (offset) * 0x04);
425         return ret;
426 }
427
428 static inline int hdmi_writel(struct hdmi_dev *hdmi_dev,
429                               u16 offset,
430                               u32 val)
431 {
432         int ret = 0;
433
434         writel_relaxed(val, hdmi_dev->regbase + (offset) * 0x04);
435         return ret;
436 }
437
438 static inline int hdmi_msk_reg(struct hdmi_dev *hdmi_dev,
439                                u16 offset, u32 msk, u32 val)
440 {
441         int ret = 0;
442         u32 temp;
443
444         temp = readl_relaxed(hdmi_dev->regbase +
445                              (offset) * 0x04) & (0xFF - (msk));
446         writel_relaxed(temp | ((val) & (msk)),
447                        hdmi_dev->regbase + (offset) * 0x04);
448         return ret;
449 }
450 static inline void rockchip_hdmiv1_reset_pclk(void)
451 {
452         writel_relaxed(0x00010001, RK_CRU_VIRT + 0x128);
453         msleep(100);
454         writel_relaxed(0x00010000, RK_CRU_VIRT + 0x128);
455 }
456
457
458
459 void rockchip_hdmiv1_dev_init_ops(struct hdmi_ops *ops);
460 int rockchip_hdmiv1_initial(struct hdmi *hdmi);
461 void rockchip_hdmiv1_irq(struct hdmi *hdmi);
462 void rockchip_hdmiv1_cec_init(struct hdmi *hdmi);
463 void rockchip_hdmiv1_cec_isr(struct hdmi_dev *hdmi_dev);
464
465 #endif