Merge remote-tracking branch 'aosp/android-3.0' into develop-3.0-jb
[firefly-linux-kernel-4.4.55.git] / drivers / video / rockchip / hdmi / rk_hdmi.h
1 #ifndef __RK_HDMI_H__
2 #define __RK_HDMI_H__
3
4 #include <linux/kernel.h>
5 #include <linux/fb.h>
6 #include <linux/spinlock.h>
7 #include <linux/mutex.h>
8 #include <linux/device.h>
9 #include <linux/workqueue.h>
10 #include <linux/display-sys.h>
11 #ifdef CONFIG_SWITCH
12 #include <linux/switch.h>
13 #endif
14 #ifdef CONFIG_HAS_EARLYSUSPEND
15 #include <linux/earlysuspend.h>
16 #endif
17 #include <asm/atomic.h>
18 #include<linux/rk_screen.h>
19 #include <linux/rk_fb.h>
20
21 /* default HDMI output video mode */
22 #define HDMI_VIDEO_DEFAULT_MODE                 HDMI_1280x720p_60Hz//HDMI_1920x1080p_60Hz
23
24 // HDMI video source
25 enum {
26         HDMI_SOURCE_LCDC0 = 0,
27         HDMI_SOURCE_LCDC1 = 1
28 };
29
30 /* default HDMI video source */
31 #ifdef CONFIG_ARCH_RK2928
32 #define HDMI_SOURCE_DEFAULT             HDMI_SOURCE_LCDC0
33 #else
34 #define HDMI_SOURCE_DEFAULT             HDMI_SOURCE_LCDC1
35 #endif
36 /* If HDMI_ENABLE, system will auto configure output mode according to EDID 
37  * If HDMI_DISABLE, system will output mode according to macro HDMI_VIDEO_DEFAULT_MODE
38  */
39 #define HDMI_AUTO_CONFIGURE                     HDMI_ENABLE
40
41 /* default HDMI output audio mode */
42 #define HDMI_AUDIO_DEFAULT_CHANNEL              2
43 #define HDMI_AUDIO_DEFAULT_RATE                 HDMI_AUDIO_FS_44100
44 #define HDMI_AUDIO_DEFAULT_WORD_LENGTH  HDMI_AUDIO_WORD_LENGTH_16bit
45 enum {
46         VIDEO_INPUT_RGB_YCBCR_444 = 0,
47         VIDEO_INPUT_YCBCR422,
48         VIDEO_INPUT_YCBCR422_EMBEDDED_SYNC,
49         VIDEO_INPUT_2X_CLOCK,
50         VIDEO_INPUT_2X_CLOCK_EMBEDDED_SYNC,
51         VIDEO_INPUT_RGB444_DDR,
52         VIDEO_INPUT_YCBCR422_DDR
53 };
54 enum {
55         VIDEO_OUTPUT_RGB444 = 0,
56         VIDEO_OUTPUT_YCBCR444,
57         VIDEO_OUTPUT_YCBCR422
58 };
59 enum {
60         VIDEO_INPUT_COLOR_RGB = 0,
61         VIDEO_INPUT_COLOR_YCBCR
62 };
63 /********************************************************************
64 **                          ½á¹¹¶¨Òå                                *
65 ********************************************************************/
66 /* HDMI video mode code according CEA-861-E*/
67 enum hdmi_video_mode
68 {
69         HDMI_640x480p_60Hz = 1,
70         HDMI_720x480p_60Hz_4_3,
71         HDMI_720x480p_60Hz_16_9,
72         HDMI_1280x720p_60Hz,
73         HDMI_1920x1080i_60Hz,           //5
74         HDMI_720x480i_60Hz_4_3,
75         HDMI_720x480i_60Hz_16_9,
76         HDMI_720x240p_60Hz_4_3,
77         HDMI_720x240p_60Hz_16_9,
78         HDMI_2880x480i_60Hz_4_3,        //10
79         HDMI_2880x480i_60Hz_16_9,
80         HDMI_2880x240p_60Hz_4_3,
81         HDMI_2880x240p_60Hz_16_9,
82         HDMI_1440x480p_60Hz_4_3,
83         HDMI_1440x480p_60Hz_16_9,       //15
84         HDMI_1920x1080p_60Hz,
85         HDMI_720x576p_50Hz_4_3,
86         HDMI_720x576p_50Hz_16_9,
87         HDMI_1280x720p_50Hz,
88         HDMI_1920x1080i_50Hz,           //20
89         HDMI_720x576i_50Hz_4_3,
90         HDMI_720x576i_50Hz_16_9,
91         HDMI_720x288p_50Hz_4_3,
92         HDMI_720x288p_50Hz_16_9,
93         HDMI_2880x576i_50Hz_4_3,        //25
94         HDMI_2880x576i_50Hz_16_9,
95         HDMI_2880x288p_50Hz_4_3,
96         HDMI_2880x288p_50Hz_16_9,
97         HDMI_1440x576p_50Hz_4_3,
98         HDMI_1440x576p_50Hz_16_9,       //30
99         HDMI_1920x1080p_50Hz,
100         HDMI_1920x1080p_24Hz,
101         HDMI_1920x1080p_25Hz,
102         HDMI_1920x1080p_30Hz,
103         HDMI_2880x480p_60Hz_4_3,        //35
104         HDMI_2880x480p_60Hz_16_9,
105         HDMI_2880x576p_50Hz_4_3,
106         HDMI_2880x576p_50Hz_16_9,
107         HDMI_1920x1080i_50Hz_2,         // V Line 1250 total
108         HDMI_1920x1080i_100Hz,          //40
109         HDMI_1280x720p_100Hz,
110         HDMI_720x576p_100Hz_4_3,
111         HDMI_720x576p_100Hz_16_9,
112         HDMI_720x576i_100Hz_4_3,
113         HDMI_720x576i_100Hz_16_9,       //45
114         HDMI_1920x1080i_120Hz,
115         HDMI_1280x720p_120Hz,
116         HDMI_720x480p_120Hz_4_3,
117         HDMI_720x480p_120Hz_16_9,       
118         HDMI_720x480i_120Hz_4_3,        //50
119         HDMI_720x480i_120Hz_16_9,
120         HDMI_720x576p_200Hz_4_3,
121         HDMI_720x576p_200Hz_16_9,
122         HDMI_720x576i_200Hz_4_3,
123         HDMI_720x576i_200Hz_16_9,       //55
124         HDMI_720x480p_240Hz_4_3,
125         HDMI_720x480p_240Hz_16_9,       
126         HDMI_720x480i_240Hz_4_3,
127         HDMI_720x480i_240Hz_16_9,
128         HDMI_1280x720p_24Hz,            //60
129         HDMI_1280x720p_25Hz,
130         HDMI_1280x720p_30Hz,
131         HDMI_1920x1080p_120Hz,
132         HDMI_1920x1080p_100Hz,
133 };
134
135 /* HDMI Video Data Color Mode */
136 enum {
137         HDMI_COLOR_RGB = 0,
138         HDMI_COLOR_YCbCr422,
139         HDMI_COLOR_YCbCr444
140 };
141
142 /* HDMI Audio type */
143 enum hdmi_audio_type
144 {
145         HDMI_AUDIO_LPCM = 1,
146         HDMI_AUDIO_AC3,
147         HDMI_AUDIO_MPEG1,
148         HDMI_AUDIO_MP3,
149         HDMI_AUDIO_MPEG2,
150         HDMI_AUDIO_AAC_LC,              //AAC
151         HDMI_AUDIO_DTS,
152         HDMI_AUDIO_ATARC,
153         HDMI_AUDIO_DSD,                 //One bit Audio
154         HDMI_AUDIO_E_AC3,
155         HDMI_AUDIO_DTS_HD,
156         HDMI_AUDIO_MLP,
157         HDMI_AUDIO_DST,
158         HDMI_AUDIO_WMA_PRO
159 };
160
161 /* I2S Fs */
162 enum hdmi_audio_fs {
163         HDMI_AUDIO_FS_32000  = 0x1,
164         HDMI_AUDIO_FS_44100  = 0x2,
165         HDMI_AUDIO_FS_48000  = 0x4,
166         HDMI_AUDIO_FS_88200  = 0x8,
167         HDMI_AUDIO_FS_96000  = 0x10,
168         HDMI_AUDIO_FS_176400 = 0x20,
169         HDMI_AUDIO_FS_192000 = 0x40
170 };
171
172 /* Audio Word Length */
173 enum hdmi_audio_word_length {
174         HDMI_AUDIO_WORD_LENGTH_16bit = 0x1,
175         HDMI_AUDIO_WORD_LENGTH_20bit = 0x2,
176         HDMI_AUDIO_WORD_LENGTH_24bit = 0x4
177 };
178
179 /* EDID block size */
180 #define HDMI_EDID_BLOCK_SIZE    128
181
182 // HDMI state machine
183 enum hdmi_state{
184         HDMI_SLEEP = 0,
185         HDMI_INITIAL,
186         WAIT_HOTPLUG,
187         READ_PARSE_EDID,
188         WAIT_HDMI_ENABLE,
189         SYSTEM_CONFIG,
190         CONFIG_VIDEO,
191         CONFIG_AUDIO,
192         PLAY_BACK,
193 };
194
195 // HDMI configuration command
196 enum hdmi_change {
197         HDMI_CONFIG_NONE = 0,
198         HDMI_CONFIG_VIDEO,
199         HDMI_CONFIG_AUDIO,
200         HDMI_CONFIG_COLOR,
201         HDMI_CONFIG_HDCP,
202         HDMI_CONFIG_ENABLE,
203         HDMI_CONFIG_DISABLE,
204         HDMI_CONFIG_DISPLAY
205 };
206
207 // HDMI Hotplug status
208 enum {
209         HDMI_HPD_REMOVED = 0,
210         HDMI_HPD_INSERT,
211         HDMI_HPD_ACTIVED
212 };
213
214 /* HDMI STATUS */
215 #define HDMI_DISABLE    0
216 #define HDMI_ENABLE             1
217 #define HDMI_UNKOWN             0xFF
218
219 /* HDMI Error Code */
220 enum hdmi_errorcode
221 {
222         HDMI_ERROR_SUCESS = 0,
223         HDMI_ERROR_FALSE,
224         HDMI_ERROR_I2C,
225         HDMI_ERROR_EDID,
226 };
227
228 /* HDMI audio parameters */
229 struct hdmi_audio {
230         u32 type;                                                       //Audio type
231         u32     channel;                                                //Audio channel number
232         u32     rate;                                                   //Audio sampling rate
233         u32     word_length;                                    //Audio data word length
234 };
235
236 struct hdmi_edid {
237         unsigned char sink_hdmi;                        //HDMI display device flag
238         unsigned char ycbcr444;                         //Display device support YCbCr444
239         unsigned char ycbcr422;                         //Display device support YCbCr422
240         unsigned char deepcolor;                        //bit3:DC_48bit; bit2:DC_36bit; bit1:DC_30bit; bit0:DC_Y444;
241         struct fb_monspecs      *specs;                 //Device spec
242         struct list_head modelist;                      //Device supported display mode list
243         struct hdmi_audio *audio;                       //Device supported audio info
244         int     audio_num;                                              //Device supported audio type number
245 };
246
247 extern const struct fb_videomode hdmi_mode[];
248 /* RK HDMI Video Configure Parameters */
249 struct hdmi_video_para {
250         int vic;
251         int input_mode;         //input video data interface
252         int input_color;        //input video color mode
253         int output_mode;        //output hdmi or dvi
254         int output_color;       //output video color mode
255 };
256 struct hdmi {
257         struct device   *dev;
258         struct clk              *hclk;                          //HDMI AHP clk
259         int             id;
260         int                     regbase;
261         int                             irq;
262         int                             regbase_phy;
263         int                             regsize_phy;
264         struct rk_lcdc_device_driver *lcdc;
265         
266         #ifdef CONFIG_SWITCH
267         struct switch_dev       switch_hdmi;
268         #endif
269         
270         struct workqueue_struct *workqueue;
271         struct delayed_work delay_work;
272         
273         spinlock_t      irq_lock;
274         struct mutex enable_mutex;
275         
276         int wait;
277         struct completion       complete;
278         
279         int suspend;
280 #ifdef CONFIG_HAS_EARLYSUSPEND
281         struct early_suspend    early_suspend;
282 #endif
283         
284         struct hdmi_edid edid;
285         int enable;                                     // Enable HDMI output or not
286         int vic;                                        // HDMI output video mode code
287         struct hdmi_audio audio;        // HDMI output audio type.
288         
289         int pwr_mode;                           // power mode
290         int hotplug;                            // hot plug status
291         int state;                                      // hdmi state machine status
292         int autoconfig;                         // if true, auto config hdmi output mode according to EDID.
293         int command;                            // HDMI configuration command
294         int display;                            // HDMI display status
295         int xscale;                                     // x direction scale value
296         int yscale;                                     // y directoon scale value
297         int tmdsclk;                            // TDMS Clock frequency
298         
299
300         int (*hdmi_removed)(void);
301         void (*control_output)(int enable);
302         int (*config_video)(struct hdmi_video_para *vpara);
303         int (*config_audio)(struct hdmi_audio *audio);
304         int (*detect_hotplug)(void);
305         // call back for edid
306         int (*read_edid)(int block, unsigned char *buff);
307
308         // call back for hdcp operatoion
309         void (*hdcp_cb)(void);
310         void (*hdcp_irq_cb)(int);
311         int (*hdcp_power_on_cb)(void);
312         void (*hdcp_power_off_cb)(void);
313 };
314
315 #define hdmi_err(dev, format, arg...)           \
316         dev_printk(KERN_ERR , dev , format , ## arg)
317
318 #ifdef HDMI_DEBUG
319 #define hdmi_dbg(dev, format, arg...)           \
320         dev_printk(KERN_INFO , dev , format , ## arg)
321 #else
322 #define hdmi_dbg(dev, format, arg...)   
323 #endif
324
325 extern struct hdmi *hdmi;
326 extern struct hdmi *hdmi_register(int extra);
327 extern void hdmi_unregister(struct hdmi *hdmi);
328 extern int hdmi_get_hotplug(void);
329 extern int hdmi_set_info(struct rk29fb_screen *screen, unsigned int vic);
330 extern void hdmi_init_lcdc(struct rk29fb_screen *screen, struct rk29lcd_info *lcd_info);
331 extern int hdmi_sys_init(void);
332 extern int hdmi_sys_parse_edid(struct hdmi* hdmi);
333 extern const char *hdmi_get_video_mode_name(unsigned char vic);
334 extern int hdmi_videomode_to_vic(struct fb_videomode *vmode);
335 extern const struct fb_videomode* hdmi_vic_to_videomode(int vic);
336 extern int hdmi_add_videomode(const struct fb_videomode *mode, struct list_head *head);
337 extern struct hdmi_video_timing * hdmi_find_mode(int vic);
338 extern int hdmi_find_best_mode(struct hdmi* hdmi, int vic);
339 extern int hdmi_ouputmode_select(struct hdmi *hdmi, int edid_ok);
340 extern int hdmi_switch_fb(struct hdmi *hdmi, int vic);
341 extern void hdmi_sys_remove(void);
342
343 #endif