4 #include <linux/kernel.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>
12 #include <linux/switch.h>
14 #ifdef CONFIG_HAS_EARLYSUSPEND
15 #include <linux/earlysuspend.h>
17 #include <asm/atomic.h>
18 #include<linux/rk_screen.h>
19 #include <linux/rk_fb.h>
21 /* default HDMI output video mode */
22 #define HDMI_VIDEO_DEFAULT_MODE HDMI_1280x720p_60Hz//HDMI_1920x1080p_60Hz
26 HDMI_SOURCE_LCDC0 = 0,
30 /* If HDMI_ENABLE, system will auto configure output mode according to EDID
31 * If HDMI_DISABLE, system will output mode according to macro HDMI_VIDEO_DEFAULT_MODE
33 #define HDMI_AUTO_CONFIGURE HDMI_DISABLE
35 /* default HDMI output audio mode */
36 #define HDMI_AUDIO_DEFAULT_CHANNEL 2
37 #define HDMI_AUDIO_DEFAULT_RATE HDMI_AUDIO_FS_44100
38 #define HDMI_AUDIO_DEFAULT_WORD_LENGTH HDMI_AUDIO_WORD_LENGTH_16bit
41 VIDEO_INPUT_RGB_YCBCR_444 = 0,
43 VIDEO_INPUT_YCBCR422_EMBEDDED_SYNC,
45 VIDEO_INPUT_2X_CLOCK_EMBEDDED_SYNC,
46 VIDEO_INPUT_RGB444_DDR,
47 VIDEO_INPUT_YCBCR422_DDR
51 VIDEO_OUTPUT_RGB444 = 0,
52 VIDEO_OUTPUT_YCBCR444,
57 VIDEO_INPUT_COLOR_RGB = 0,
58 VIDEO_INPUT_COLOR_YCBCR
60 /********************************************************************
62 ********************************************************************/
63 /* HDMI video mode code according CEA-861-E*/
66 HDMI_640x480p_60Hz = 1,
67 HDMI_720x480p_60Hz_4_3,
68 HDMI_720x480p_60Hz_16_9,
70 HDMI_1920x1080i_60Hz, //5
71 HDMI_720x480i_60Hz_4_3,
72 HDMI_720x480i_60Hz_16_9,
73 HDMI_720x240p_60Hz_4_3,
74 HDMI_720x240p_60Hz_16_9,
75 HDMI_2880x480i_60Hz_4_3, //10
76 HDMI_2880x480i_60Hz_16_9,
77 HDMI_2880x240p_60Hz_4_3,
78 HDMI_2880x240p_60Hz_16_9,
79 HDMI_1440x480p_60Hz_4_3,
80 HDMI_1440x480p_60Hz_16_9, //15
82 HDMI_720x576p_50Hz_4_3,
83 HDMI_720x576p_50Hz_16_9,
85 HDMI_1920x1080i_50Hz, //20
86 HDMI_720x576i_50Hz_4_3,
87 HDMI_720x576i_50Hz_16_9,
88 HDMI_720x288p_50Hz_4_3,
89 HDMI_720x288p_50Hz_16_9,
90 HDMI_2880x576i_50Hz_4_3, //25
91 HDMI_2880x576i_50Hz_16_9,
92 HDMI_2880x288p_50Hz_4_3,
93 HDMI_2880x288p_50Hz_16_9,
94 HDMI_1440x576p_50Hz_4_3,
95 HDMI_1440x576p_50Hz_16_9, //30
100 HDMI_2880x480p_60Hz_4_3, //35
101 HDMI_2880x480p_60Hz_16_9,
102 HDMI_2880x576p_50Hz_4_3,
103 HDMI_2880x576p_50Hz_16_9,
104 HDMI_1920x1080i_50Hz_2, // V Line 1250 total
105 HDMI_1920x1080i_100Hz, //40
106 HDMI_1280x720p_100Hz,
107 HDMI_720x576p_100Hz_4_3,
108 HDMI_720x576p_100Hz_16_9,
109 HDMI_720x576i_100Hz_4_3,
110 HDMI_720x576i_100Hz_16_9, //45
111 HDMI_1920x1080i_120Hz,
112 HDMI_1280x720p_120Hz,
113 HDMI_720x480p_120Hz_4_3,
114 HDMI_720x480p_120Hz_16_9,
115 HDMI_720x480i_120Hz_4_3, //50
116 HDMI_720x480i_120Hz_16_9,
117 HDMI_720x576p_200Hz_4_3,
118 HDMI_720x576p_200Hz_16_9,
119 HDMI_720x576i_200Hz_4_3,
120 HDMI_720x576i_200Hz_16_9, //55
121 HDMI_720x480p_240Hz_4_3,
122 HDMI_720x480p_240Hz_16_9,
123 HDMI_720x480i_240Hz_4_3,
124 HDMI_720x480i_240Hz_16_9,
125 HDMI_1280x720p_24Hz, //60
128 HDMI_1920x1080p_120Hz,
129 HDMI_1920x1080p_100Hz,
132 /* HDMI Video Data Color Mode */
139 /* HDMI Audio type */
147 HDMI_AUDIO_AAC_LC, //AAC
150 HDMI_AUDIO_DSD, //One bit Audio
160 HDMI_AUDIO_FS_32000 = 0x1,
161 HDMI_AUDIO_FS_44100 = 0x2,
162 HDMI_AUDIO_FS_48000 = 0x4,
163 HDMI_AUDIO_FS_88200 = 0x8,
164 HDMI_AUDIO_FS_96000 = 0x10,
165 HDMI_AUDIO_FS_176400 = 0x20,
166 HDMI_AUDIO_FS_192000 = 0x40
169 /* Audio Word Length */
170 enum hdmi_audio_word_length {
171 HDMI_AUDIO_WORD_LENGTH_16bit = 0x1,
172 HDMI_AUDIO_WORD_LENGTH_20bit = 0x2,
173 HDMI_AUDIO_WORD_LENGTH_24bit = 0x4
176 /* EDID block size */
177 #define HDMI_EDID_BLOCK_SIZE 128
179 // HDMI state machine
192 // HDMI configuration command
194 HDMI_CONFIG_NONE = 0,
204 // HDMI Hotplug status
206 HDMI_HPD_REMOVED = 0,
212 #define HDMI_DISABLE 0
213 #define HDMI_ENABLE 1
214 #define HDMI_UNKOWN 0xFF
216 /* HDMI Error Code */
219 HDMI_ERROR_SUCESS = 0,
225 /* HDMI audio parameters */
227 u32 type; //Audio type
228 u32 channel; //Audio channel number
229 u32 rate; //Audio sampling rate
230 u32 word_length; //Audio data word length
234 unsigned char sink_hdmi; //HDMI display device flag
235 unsigned char ycbcr444; //Display device support YCbCr444
236 unsigned char ycbcr422; //Display device support YCbCr422
237 unsigned char deepcolor; //bit3:DC_48bit; bit2:DC_36bit; bit1:DC_30bit; bit0:DC_Y444;
238 struct fb_monspecs *specs; //Device spec
239 struct list_head modelist; //Device supported display mode list
240 struct hdmi_audio *audio; //Device supported audio info
241 int audio_num; //Device supported audio type number
242 int base_audio_support; //Device supported base audio
245 /* RK HDMI Video Configure Parameters */
246 struct hdmi_video_para {
248 int input_mode; //input video data interface
249 int input_color; //input video color mode
250 int output_mode; //output hdmi or dvi
251 int output_color; //output video color mode
256 struct clk *hclk; //HDMI AHP clk
262 struct rk_lcdc_device_driver *lcdc;
265 struct switch_dev switch_hdmi;
268 struct workqueue_struct *workqueue;
269 struct delayed_work delay_work;
272 struct mutex enable_mutex;
275 struct completion complete;
278 #ifdef CONFIG_HAS_EARLYSUSPEND
279 struct early_suspend early_suspend;
282 struct hdmi_edid edid;
283 int enable; // Enable HDMI output or not
284 int vic; // HDMI output video mode code
285 struct hdmi_audio audio; // HDMI output audio type.
287 int pwr_mode; // power mode
288 int hotplug; // hot plug status
289 int state; // hdmi state machine status
290 int autoconfig; // if true, auto config hdmi output mode according to EDID.
291 int command; // HDMI configuration command
292 int display; // HDMI display status
293 int xscale; // x direction scale value
294 int yscale; // y directoon scale value
295 int tmdsclk; // TDMS Clock frequency
299 void (*control_output)(int enable);
300 int (*config_video)(struct hdmi_video_para *vpara);
301 int (*config_audio)(struct hdmi_audio *audio);
302 int (*detect_hotplug)(void);
303 // call back for edid
304 int (*read_edid)(int block, unsigned char *buff);
305 int (*set_vif)(rk_screen * screen,bool connect);
307 // call back for hdcp operatoion
308 void (*hdcp_cb)(void);
309 void (*hdcp_irq_cb)(int);
310 int (*hdcp_power_on_cb)(void);
311 void (*hdcp_power_off_cb)(void);
314 #define hdmi_err(dev, format, arg...) \
315 dev_printk(KERN_ERR , dev , format , ## arg)
318 #define hdmi_dbg(dev, format, arg...) \
319 dev_printk(KERN_INFO , dev , format , ## arg)
321 #define hdmi_dbg(dev, format, arg...)
324 extern struct hdmi *hdmi;
325 extern int hdmi_get_hotplug(void);
326 extern int hdmi_set_info(struct rk29fb_screen *screen, unsigned int vic);
327 extern void hdmi_init_lcdc(struct rk29fb_screen *screen, struct rk29lcd_info *lcd_info);
328 extern int hdmi_sys_init(void);
329 extern int hdmi_sys_parse_edid(struct hdmi* hdmi);
330 extern const char *hdmi_get_video_mode_name(unsigned char vic);
331 extern int hdmi_videomode_to_vic(struct fb_videomode *vmode);
332 extern const struct fb_videomode* hdmi_vic_to_videomode(int vic);
333 extern int hdmi_add_videomode(const struct fb_videomode *mode, struct list_head *head);
334 extern struct hdmi_video_timing * hdmi_find_mode(int vic);
335 extern int hdmi_find_best_mode(struct hdmi* hdmi, int vic);
336 extern int hdmi_ouputmode_select(struct hdmi *hdmi, int edid_ok);
337 extern int hdmi_switch_fb(struct hdmi *hdmi, int vic);
338 extern void hdmi_work(struct work_struct *work);