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