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 <linux/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
24 #define HDMI_720X480P_60HZ_VIC 2
25 #define HDMI_720X480I_60HZ_VIC 6
26 #define HDMI_720X576P_50HZ_VIC 17
27 #define HDMI_720X576I_50HZ_VIC 21
28 #define HDMI_1280X720P_50HZ_VIC 19
29 #define HDMI_1280X720P_60HZ_VIC 4
30 #define HDMI_1920X1080P_50HZ_VIC 31
31 #define HDMI_1920X1080I_50HZ_VIC 20
32 #define HDMI_1920X1080P_60HZ_VIC 16
33 #define HDMI_1920X1080I_60HZ_VIC 5
34 #define HDMI_3840X2160P_24HZ_VIC 93
35 #define HDMI_3840X2160P_25HZ_VIC 94
36 #define HDMI_3840X2160P_30HZ_VIC 95
37 #define HDMI_3840X2160P_50HZ_VIC 96
38 #define HDMI_3840X2160P_60HZ_VIC 97
39 #define HDMI_4096X2160P_24HZ_VIC 98
40 #define HDMI_4096X2160P_25HZ_VIC 99
41 #define HDMI_4096X2160P_30HZ_VIC 100
42 #define HDMI_4096X2160P_50HZ_VIC 101
43 #define HDMI_4096X2160P_60HZ_VIC 102
45 /* HDMI video source */
47 HDMI_SOURCE_LCDC0 = 0,
57 * If HDMI_ENABLE, system will auto configure output mode according to EDID
58 * If HDMI_DISABLE, system will output mode according to
59 * macro HDMI_VIDEO_DEFAULT_MODE
61 #define HDMI_AUTO_CONFIGURE HDMI_DISABLE
63 /* default HDMI output audio mode */
64 #define HDMI_AUDIO_DEFAULT_CHANNEL 2
65 #define HDMI_AUDIO_DEFAULT_RATE HDMI_AUDIO_FS_44100
66 #define HDMI_AUDIO_DEFAULT_WORD_LENGTH HDMI_AUDIO_WORD_LENGTH_16bit
69 VIDEO_INPUT_RGB_YCBCR_444 = 0,
71 VIDEO_INPUT_YCBCR422_EMBEDDED_SYNC,
73 VIDEO_INPUT_2X_CLOCK_EMBEDDED_SYNC,
74 VIDEO_INPUT_RGB444_DDR,
75 VIDEO_INPUT_YCBCR422_DDR
79 VIDEO_OUTPUT_RGB444 = 0,
80 VIDEO_OUTPUT_YCBCR444,
81 VIDEO_OUTPUT_YCBCR422,
86 VIDEO_INPUT_COLOR_RGB = 0,
87 VIDEO_INPUT_COLOR_YCBCR444,
88 VIDEO_INPUT_COLOR_YCBCR422,
89 VIDEO_INPUT_COLOR_YCBCR420
92 /* HDMI video mode code according CEA-861-E */
93 enum hdmi_video_mode {
94 HDMI_640x480p_60Hz = 1,
95 HDMI_720x480p_60Hz_4_3,
96 HDMI_720x480p_60Hz_16_9,
98 HDMI_1920x1080i_60Hz, /* 5 */
99 HDMI_720x480i_60Hz_4_3,
100 HDMI_720x480i_60Hz_16_9,
101 HDMI_720x240p_60Hz_4_3,
102 HDMI_720x240p_60Hz_16_9,
103 HDMI_2880x480i_60Hz_4_3, /* 10 */
104 HDMI_2880x480i_60Hz_16_9,
105 HDMI_2880x240p_60Hz_4_3,
106 HDMI_2880x240p_60Hz_16_9,
107 HDMI_1440x480p_60Hz_4_3,
108 HDMI_1440x480p_60Hz_16_9, /* 15 */
109 HDMI_1920x1080p_60Hz,
110 HDMI_720x576p_50Hz_4_3,
111 HDMI_720x576p_50Hz_16_9,
113 HDMI_1920x1080i_50Hz, /* 20 */
114 HDMI_720x576i_50Hz_4_3,
115 HDMI_720x576i_50Hz_16_9,
116 HDMI_720x288p_50Hz_4_3,
117 HDMI_720x288p_50Hz_16_9,
118 HDMI_2880x576i_50Hz_4_3, /* 25 */
119 HDMI_2880x576i_50Hz_16_9,
120 HDMI_2880x288p_50Hz_4_3,
121 HDMI_2880x288p_50Hz_16_9,
122 HDMI_1440x576p_50Hz_4_3,
123 HDMI_1440x576p_50Hz_16_9, /* 30 */
124 HDMI_1920x1080p_50Hz,
125 HDMI_1920x1080p_24Hz,
126 HDMI_1920x1080p_25Hz,
127 HDMI_1920x1080p_30Hz,
128 HDMI_2880x480p_60Hz_4_3, /* 35 */
129 HDMI_2880x480p_60Hz_16_9,
130 HDMI_2880x576p_50Hz_4_3,
131 HDMI_2880x576p_50Hz_16_9,
132 HDMI_1920x1080i_50Hz_2, /* V Line 1250 total */
133 HDMI_1920x1080i_100Hz, /* 40 */
134 HDMI_1280x720p_100Hz,
135 HDMI_720x576p_100Hz_4_3,
136 HDMI_720x576p_100Hz_16_9,
137 HDMI_720x576i_100Hz_4_3,
138 HDMI_720x576i_100Hz_16_9, /* 45 */
139 HDMI_1920x1080i_120Hz,
140 HDMI_1280x720p_120Hz,
141 HDMI_720x480p_120Hz_4_3,
142 HDMI_720x480p_120Hz_16_9,
143 HDMI_720x480i_120Hz_4_3, /* 50 */
144 HDMI_720x480i_120Hz_16_9,
145 HDMI_720x576p_200Hz_4_3,
146 HDMI_720x576p_200Hz_16_9,
147 HDMI_720x576i_200Hz_4_3,
148 HDMI_720x576i_200Hz_16_9, /* 55 */
149 HDMI_720x480p_240Hz_4_3,
150 HDMI_720x480p_240Hz_16_9,
151 HDMI_720x480i_240Hz_4_3,
152 HDMI_720x480i_240Hz_16_9,
153 HDMI_1280x720p_24Hz, /* 60 */
156 HDMI_1920x1080p_120Hz,
157 HDMI_1920x1080p_100Hz,
160 /* HDMI Video Data Color Mode */
167 /* HDMI Video Color Depth */
169 HDMI_COLOR_DEPTH_8BIT = 0x1,
170 HDMI_COLOR_DEPTH_10BIT = 0x2,
171 HDMI_COLOR_DEPTH_12BIT = 0x4,
172 HDMI_COLOR_DEPTH_16BIT = 0x8
175 /* HDMI Audio type */
176 enum hdmi_audio_type {
182 HDMI_AUDIO_AAC_LC, /* AAC */
185 HDMI_AUDIO_DSD, /* One bit Audio */
195 HDMI_AUDIO_FS_32000 = 0x1,
196 HDMI_AUDIO_FS_44100 = 0x2,
197 HDMI_AUDIO_FS_48000 = 0x4,
198 HDMI_AUDIO_FS_88200 = 0x8,
199 HDMI_AUDIO_FS_96000 = 0x10,
200 HDMI_AUDIO_FS_176400 = 0x20,
201 HDMI_AUDIO_FS_192000 = 0x40
204 /* Audio Word Length */
205 enum hdmi_audio_word_length {
206 HDMI_AUDIO_WORD_LENGTH_16bit = 0x1,
207 HDMI_AUDIO_WORD_LENGTH_20bit = 0x2,
208 HDMI_AUDIO_WORD_LENGTH_24bit = 0x4
211 /* EDID block size */
212 #define HDMI_EDID_BLOCK_SIZE 128
214 /* HDMI state machine */
227 /* HDMI configuration command */
229 HDMI_CONFIG_NONE = 0,
239 /* HDMI Hotplug status */
241 HDMI_HPD_REMOVED = 0,
247 #define HDMI_DISABLE 0
248 #define HDMI_ENABLE 1
249 #define HDMI_UNKOWN 0xFF
251 /* HDMI Error Code */
252 enum hdmi_errorcode {
253 HDMI_ERROR_SUCESS = 0,
259 /* HDMI audio parameters */
261 u32 type; /* Audio type */
262 u32 channel; /* Audio channel number */
263 u32 rate; /* Audio sampling rate */
264 u32 word_length; /* Audio data word length */
268 unsigned char sink_hdmi; /* HDMI display device flag */
269 unsigned char ycbcr444; /* Display device support YCbCr444 */
270 unsigned char ycbcr422; /* Display device support YCbCr422 */
271 unsigned char deepcolor; /* bit3:DC_48bit; bit2:DC_36bit;
272 * bit1:DC_30bit; bit0:DC_Y444;
274 unsigned char latency_fields_present;
275 unsigned char i_latency_fields_present;
276 unsigned char video_latency;
277 unsigned char audio_latency;
278 unsigned char interlaced_video_latency;
279 unsigned char interlaced_audio_latency;
280 unsigned char video_present; /* have additional video format
281 * abount 4k and/or 3d
283 unsigned char support_3d; /* 3D format support */
284 unsigned int maxtmdsclock; /* max tmds clock freq support */
285 struct fb_monspecs *specs; /* Device spec */
286 struct list_head modelist; /* Device supported display mode list */
287 struct hdmi_audio *audio; /* Device supported audio info */
288 int audio_num; /* Device supported audio type number */
289 int base_audio_support; /* Device supported base audio */
290 unsigned int cecaddress; /* CEC physical address */
293 /* RK HDMI Video Configure Parameters */
294 struct hdmi_video_para {
296 int input_mode; /* input video data interface */
297 int input_color; /* input video color mode */
298 int output_mode; /* output hdmi or dvi */
299 int output_color; /* output video color mode */
300 unsigned char format_3d; /* output 3d format */
301 unsigned char color_depth; /* color depth: 8bit; 10bit;
304 unsigned char pixel_repet; /* pixel repettion */
305 unsigned char pixel_pack_phase; /* pixel packing default phase */
306 unsigned char color_limit_range; /* quantization range
307 * 0: full range(0~255)
308 * 1:limit range(16~235)
312 struct rk_hdmi_drvdata {
321 struct rk_lcdc_driver *lcdc;
322 struct rk_hdmi_drvdata *data;
323 struct rk_display_device *ddev;
325 struct switch_dev switch_hdmi;
328 struct workqueue_struct *workqueue;
329 struct delayed_work delay_work;
332 struct mutex enable_mutex;
335 struct completion complete;
338 #ifdef CONFIG_HAS_EARLYSUSPEND
339 struct early_suspend early_suspend;
342 struct hdmi_edid edid;
343 int enable; /* Enable HDMI output or not */
344 int vic; /* HDMI output video mode code */
345 struct hdmi_audio audio; /* HDMI output audio type */
347 int pwr_mode; /* power mode */
348 int hotplug; /* hot plug status */
349 int state; /* hdmi state machine status */
350 int autoconfig; /* if true, auto config hdmi output mode
353 int command; /* HDMI configuration command */
354 int display; /* HDMI display status */
355 int xscale; /* x direction scale value */
356 int yscale; /* y directoon scale value */
357 int tmdsclk; /* TDMS Clock frequency */
358 int pixclock; /* Pixel Clcok frequency */
360 struct list_head pwrlist_head;
362 int (*insert)(struct hdmi *hdmi);
363 int (*remove)(struct hdmi *hdmi);
364 void (*control_output)(struct hdmi *hdmi, int enable);
365 int (*config_video)(struct hdmi *hdmi,
366 struct hdmi_video_para *vpara);
367 int (*config_audio)(struct hdmi *hdmi, struct hdmi_audio *audio);
368 int (*detect_hotplug)(struct hdmi *hdmi);
369 /* call back for edid */
370 int (*read_edid)(struct hdmi *hdmi, int block, unsigned char *buff);
371 int (*set_vif)(struct hdmi *hdmi, struct rk_screen *screen,
374 /* call back for hdcp operation */
375 void (*hdcp_cb)(void);
376 void (*hdcp_irq_cb)(int);
377 int (*hdcp_power_on_cb)(void);
378 void (*hdcp_power_off_cb)(void);
380 /*call back for cec operation*/
381 void (*cec_irq)(void);
382 void (*cec_set_device_pa)(int);
383 int (*cec_enumerate)(void);
386 #define hdmi_err(dev, format, arg...) \
387 dev_err(dev , format , ## arg)
390 #define hdmi_dbg(dev, format, arg...) \
391 dev_info(dev , format , ## arg)
393 #define hdmi_dbg(dev, format, arg...)
396 int hdmi_drv_register(struct hdmi *hdmi_drv);
397 int hdmi_get_hotplug(void);
398 int hdmi_set_info(struct rk_screen *screen, unsigned int vic);
399 void hdmi_init_lcdc(struct rk_screen *screen,
400 struct rk29lcd_info *lcd_info);
401 int hdmi_sys_init(struct hdmi *hdmi_drv);
402 int hdmi_sys_parse_edid(struct hdmi *hdmi_drv);
403 const char *hdmi_get_video_mode_name(unsigned char vic);
404 int hdmi_videomode_to_vic(struct fb_videomode *vmode);
405 const struct fb_videomode *hdmi_vic_to_videomode(int vic);
406 int hdmi_add_videomode(const struct fb_videomode *mode,
407 struct list_head *head);
408 struct hdmi_video_timing *hdmi_find_mode(int vic);
409 int hdmi_find_best_mode(struct hdmi *hdmi_drv, int vic);
410 int hdmi_ouputmode_select(struct hdmi *hdmi_drv, int edid_ok);
411 int hdmi_switch_fb(struct hdmi *hdmi_drv, int vic);
412 int hdmi_init_video_para(struct hdmi *hdmi_drv,
413 struct hdmi_video_para *video);
414 void hdmi_work(struct work_struct *work);
415 void hdmi_register_display_sysfs(struct hdmi *hdmi_drv,
416 struct device *parent);
417 void hdmi_unregister_display_sysfs(struct hdmi *hdmi_drv);
419 int rk_hdmi_parse_dt(struct hdmi *hdmi_drv);
420 int rk_hdmi_pwr_enable(struct hdmi *dev_drv);
421 int rk_hdmi_pwr_disable(struct hdmi *dev_drv);