1 /* Description: ch7033-35 interface */
7 /* --------------- TIMING INFORMATION ----------------------- */
9 uint32 ht
; /* horizontal tatal pixels */
10 uint32 ha
; /* horizontal active pixels */
11 uint32 ho
; /* horizontal offset (back porch) */
12 uint32 hw
; /* horizontal sync pulse width */
13 uint32 vt
; /* vertical total lines */
14 uint32 va
; /* vertical active lines */
15 uint32 vo
; /* vertical offset (back porch) */
16 uint32 vw
; /* vertical sync pulse width */
17 } CH703x_TIMING
, *PCH703x_TIMING
;
19 /* --------------- INPUT INFORMATION ----------------------- */
20 /* pixel format for input */
21 #define PIXEL_FMT_RGB888 0 /* RGB 888 format (24-bit) */
22 #define PIXEL_FMT_RGB666 1 /* RGB 666 format (18-bit) */
23 #define PIXEL_FMT_RGB565 2 /* RGB 565 format (16-bit) */
24 #define PIXEL_FMT_RGB555 3 /* RGB 555 format (16-bit) */
25 #define PIXEL_FMT_RGBDVO 4 /* RGB DVO */
26 #define PIXEL_FMT_YUV422_8 5 /* YCbCr 4:2:2 8-bit */
27 #define PIXEL_FMT_YUV422_10 6 /* YCbCr 4:2:2 10-bit */
28 #define PIXEL_FMT_YUV444 7 /* YCbCr 4:4:4 8-bit */
29 #define PIXEL_FMT_RGB666_C 9 /* consecutive RGB666 */
30 #define PIXEL_FMT_RGB565_C 10 /* consecutive RGB565 */
31 #define PIXEL_FMT_RGB555_C 11 /* consecutive RGB555 */
33 /* polarity and invert */
39 /* audio input type */
43 #define SPDIF_MOD_DIFF 0
44 #define SPDIF_MOD_CMOS 1
46 /* I2S audio format */
48 #define I2S_FMT_RTJ 1 /* right justified */
49 #define I2S_FMT_LTJ 2 /* left justified */
51 #define I2S_LEN_16B 0 /* 16 - bit */
52 #define I2S_LEN_20B 1 /* 20 - bit */
53 #define I2S_LEN_24B 2 /* 24 - bit */
56 IF_PRO
= 0, /* progressive video interface */
57 IF_INT
, /* interlace video interface */
58 IF_CPU
, /* video interface like CPU data interface */
61 /* Multi 2x format: */
62 #define M2X_SEQ_NO_INV 0
63 #define M2X_SEQ_INVERT 1
64 #define M2X_ALIGH_LBIT 0
65 #define M2X_ALIGH_HBIT 1
68 uint8 halfword_swap
; /* halfword swap: refer to "SWP_PAPB" in datasheet */
69 uint8 halfword_align
; /* halfword align select: refer to "AH_LB" in datasheet */
70 uint8 yc_swap
; /* indicate Y and C swap (only for BT656 input) */
74 /* Multi 3x format; */
75 #define M3X_ALIGH_LBIT 0
76 #define M3X_ALIGH_MBIT 1
77 #define M3X_ALIGH_HBIT 2
80 uint8 byte_align
; /* byte align: refer to "POS3X" in datasheet */
88 /* input pixel format byte swap, byte_swap */
89 #define BYTE_SWAP_RGB 0
90 #define BYTE_SWAP_RBG 1
91 #define BYTE_SWAP_GRB 2
92 #define BYTE_SWAP_GBR 3
93 #define BYTE_SWAP_BRG 4
94 #define BYTE_SWAP_BGR 5
97 uint8 format
; /* input data format, refer to IDF in datasheet */
98 uint8 bit_swap
; /* select bit swap for each byte, refer to REVERSE in datasheet */
99 uint8 byte_swap
; /* R-G-B or Y-Pb-Pr swap, refer to SWAP in datasheet */
100 uint8 byte_align
; /* MSB align or LSB align, refer to HIGH in datasheet */
101 uint8 multiplexed
; /* indicate if data is multiplexed: refer to MULTI in datasheet */
102 uint8 embedded_sync
; /* indicate if embedded sync is used */
104 M2X_FMT m2x_fmt
; /* multiplexed 2x data properties */
105 M3X_FMT m3x_fmt
; /* multiplexed 3x data properties */
106 } PIXEL_FMT
, *PPIXEL_FMT
;
109 IF_TYPE if_type
; /* interface type */
110 CH703x_TIMING timing
;
111 uint32 pclk_khz
; /* pixel clock frequecy */
113 uint8 hs_pol
; /* horizontal sync polarity */
114 uint8 vs_pol
; /* vertical sync polarity */
115 uint8 de_pol
; /* data enable polarity */
117 uint8 audio_type
; /* 0: spdif - 1: i2s */
118 uint8 spdif_mode
; /* 0: differential mode - 1: cmos mode */
122 /* if using crystal: */
123 uint8 crystal_used
; /* 0: no crystal - 1: using crystal */
126 } CH703x_INPUT_INFO
, *PCH703x_INPUT_INFO
;
128 /* --------------- OUTPUT INFORMATION ----------------------- */
129 /* channel bit define: */
130 #define LVDS_DATA0_SEL 0
131 #define LVDS_DATA1_SEL 1
132 #define LVDS_DATA2_SEL 2
133 #define LVDS_DATA3_SEL 3
134 #define LVDS_CLOCK_SEL 4
136 #define LVDS_CHANNEL_SWAP_DEF 0
137 #define LVDS_CHANNEL_SWAP_OP1 1
139 #define LVDS_SPWG_T1_MIN 1
140 #define LVDS_SPWG_T1_MAX 50
141 #define LVDS_SPWG_T2_MIN 200
142 #define LVDS_SPWG_T2_MAX 1023
143 #define LVDS_SPWG_T3_MIN 200
144 #define LVDS_SPWG_T3_MAX 1023
145 #define LVDS_SPWG_T4_MIN 1
146 #define LVDS_SPWG_T4_MAX 50
147 #define LVDS_SPWG_T5_MIN 200
148 #define LVDS_SPWG_T5_MAX 1023
150 /* value of pwm_freq, Hz */
151 #define IDX_PWM_FREQ_100Hz 100
152 #define IDX_PWM_FREQ_200Hz 200
153 #define IDX_PWM_FREQ_2KHz 2000
154 #define IDX_PWM_FREQ_4KHz 4000
155 #define IDX_PWM_FREQ_16KHz 16000
156 #define IDX_PWM_FREQ_32KHz 32000
157 #define IDX_PWM_FREQ_64KHz 64000
158 #define IDX_PWM_FREQ_128KHz 128000
161 uint8 bypass
; /* indicate if bypass function enabled */
162 uint8 channel_swap
; /* refer to spec: HD_LV_SEQ */
163 uint8 channel_pol
; /* channel polarity */
164 uint8 hs_pol
; /* hsync polarity */
165 uint8 vs_pol
; /* vsync polarity */
166 uint8 de_pol
; /* de polarity */
167 /* externed at 2011.05.25 */
168 uint8 pwm_duty
; /* pwm duty-cycle 0~255 */
169 uint8 pwm_inv
; /* pwm inverter POL_INVERT or POL_NO_INV */
170 uint32 pwm_freq
; /* pwm frequency, which should be 100Hz, 200Hz, 2kHz, 4KHz, 16Khz, 32KHZ, 64KHz, 128KHz */
171 uint32 spwg_t1
; /* power sequency of T1 */
172 uint32 spwg_t2
; /* power sequency of T2 */
173 uint32 spwg_t3
; /* power sequency of T3 */
174 uint32 spwg_t4
; /* power sequency of T4 */
175 uint32 spwg_t5
; /* power sequency of T5 */
176 } LVDS_FMT
, *PLVDS_FMT
;
178 /* aspect ratio, These do not match the EDID encoding */
179 #define AS_RATIO_NA 0 /* support */
180 #define AS_RATIO_4_3 1 /* support */
181 #define AS_RATIO_16_9 2 /* support */
182 #define AS_RATIO_16_10 3 /* not support */
183 #define AS_RATIO_5_4 4 /* not support */
185 /* hdmi channel swap selection, description "channel_swap" in HDMI_FMT below: */
186 /* here only define default macro, for other condition, use number directly... */
187 #define HDMI_CHANNEL_SWAP_DEF 0
190 uint8 bypass
; /* indicate if bypass mode enabled */
191 uint8 is_dvi_mode
; /* indicate if DVI mode required */
192 uint8 format_index
; /* VIC index */
193 uint8 aspect_ratio
; /* 1: 4:3 - 2: 16:9 */
194 uint8 channel_swap
; /* refer to "HD_LV_SEQ" in datasheet. */
195 uint8 data_pol_invert
; /* if invert the polarity of input of HDMI module, refer to HD_LV_POL in spec. */
196 uint8 hs_pol
; /* HDMI output horizontal sync polarity */
197 uint8 vs_pol
; /* HDMI output vertical sync polarity */
198 } HDMI_FMT
, *PHDMI_FMT
;
200 /* vga channel swap selection, descript "channel_swap" in VGA_FMT below: */
201 /* here only define default macro, for other condition, use number directly... */
202 #define VGA_CHANNEL_SWAP_DEF 0
204 /* vga sync swap selection, descript "sync_swap" in VGA_FMT below: */
205 /* here only define default macro, for other condition, use number directly... */
206 #define VGA_SYNC_SWAP_DEF 0
208 #define VGA_CSYNC_XOR 0
209 #define VGA_CSYNC_OR 1
210 #define VGA_CSYNC_AND 2
213 uint8 bypass
; /* indicate if bypass function enabled */
214 uint8 channel_swap
; /* R G B swap control, refer to "DACSP" in datasheet */
215 uint8 sync_swap
; /* sync swap control, refer to "SYNCS" in datasheet */
216 uint8 csync_type
; /* CSync type */
217 uint8 hs_pol
; /* horizontal sync polarity */
218 uint8 vs_pol
; /* vetical sync polairy */
219 uint8 de_pol
; /* Data enable signal polarity */
221 } VGA_FMT
, *PVGA_FMT
;
223 /* hdtv channel swap selection, descript "channel_swap" in HDTV_FMT below: */
224 /* here only define default macro, for other condition, use number directly... */
225 #define HDTV_CHANNEL_SWAP_DEF 0
228 uint8 bypass
; /* indicate if bypass function enabled */
229 uint8 format_index
; /* refer to datasheet */
230 uint8 channel_swap
; /* Y Pb Pr channel swap, refer to "DACSP" in datasheet */
232 } HDTV_FMT
, *PHDTV_FMT
;
234 /* channel bits, output channel */
235 #define CHANNEL_LVDS 0x01
236 #define CHANNEL_HDMI 0x02
237 #define CHANNEL_VGA 0x04
238 #define CHANNEL_HDTV 0x08
239 #define CHANNEL_VGA1 0x10
240 /* channel bits, input channel */
241 #define CHANNEL_INPUTLOST 0x20
248 #define DOWN_SCALING_MAX 80 /* -+wyc, [0..80]. 0=100%, no down scaling; 80=down scale to 20% in size */
251 CH703x_TIMING timing
; /* Timing */
252 uint32 uclk_khz
; /* output clock frequency */
253 uint8 channel
; /* combined channel bits */
255 LVDS_FMT lvds_fmt
; /* LVDS special format if output to LVDS */
256 HDMI_FMT hdmi_fmt
; /* HDMI special format if output to LVDS */
257 VGA_FMT vga_fmt
; /* VGA special format if output to LVDS */
258 HDTV_FMT hdtv_fmt
; /* HDTV special format if output to LVDS */
261 uint8 ds_percent_h
; /* down scaling percent for horizontal direction */
262 uint8 ds_percent_v
; /* down scaling percent for vertical direction */
263 uint8 rotate
; /* Rotation control */
264 uint8 h_flip
; /* Horizontal flip control */
265 uint8 v_flip
; /* Vertical flip control */
267 } CH703x_OUTPUT_INFO
, *PCH703x_OUTPUT_INFO
;
269 /* get which panel's EDID, currently only support reading EDID from HDMI or VGA */
270 #define GET_VGA_EDID 0x80
271 #define GET_HDMI_EDID 0x00
272 #define GET_EDID_MASK 0x80
274 /* --------------- DEVICE INFORMATION ----------------------- */
284 DEV_UNKNOW
, /* always be the last */
287 typedef struct _FW703X_CFG
{
288 unsigned char size
; /* total size <=16 bytes, currently 7 bytes */
289 unsigned char ver_major
; /* MCU firmware version */
290 unsigned char ver_minor
;
291 unsigned char did
; /* device id */
292 unsigned char rid
; /* revision id */
293 unsigned char capbility
; /* Firmware capability; */
294 unsigned char reserved
;
295 unsigned char reserve2
;
298 /* ------------------ Interface -------------------------------- */
304 /* open I2C device before calling any of the following functions */
307 /* 0..DEV_UNKNOW-1: check whether the specified device present */
308 /* DEV_UNKNOW: check which device present */
310 /* 0..DEV_UNKNOW-1: the device present */
311 /* DEV_UNKNOW: not found device present */
312 CH703x_DEV_TYPE
ch_check_chip(CH703x_DEV_TYPE chip
);
314 /* start firmware before calling any other functions */
315 int32
ch_start_firmware(CH703x_DEV_TYPE chip
);
317 /* get MCU information */
318 int32
ch_getMcuVersion(CH703x_DEV_TYPE chip
, FW703X_CFG
* cfg
);
320 /* load the firmware of ch703x */
321 int32
ch_load_firmware(CH703x_DEV_TYPE chip
, uint8
*fw
, uint16 size
);
323 /* set ch703x working mode */
324 /* this function also sets these features: scaling down, rotation or flip */
325 int32
ch_set_mode(CH703x_DEV_TYPE chip
, CH703x_INPUT_INFO
* in
, CH703x_OUTPUT_INFO
* out
);
327 /* force ch703x to output color bar(generated by itself) instead of the input. */
328 /* ch_set_mode() should be successfully called before calling this function. */
330 int32
ch_set_test_mode(CH703x_DEV_TYPE chip
);
332 /* get edid from VGA pannel or HDMI pannel */
334 /* buf: buffer to store EDID, >= 256 bytes, 512 bytes recommended. */
335 /* len: buffer length */
336 /* whichEDID: GET_VGA_EDID or GET_HDMI_EDID */
337 int32
ch_get_edid(CH703x_DEV_TYPE chip
, uint8
*buf
, uint16 len
, uint8 whichEDID
);
339 #define VGA_HOTPLUG_DELAY 50 /* unit ms */
340 /* For output channel, currently only support HDMI and VGA hotplg detecting, */
341 /* could not detect HDTV, VGA1, LVDS hotplug. */
342 /* For input channel, currently support input channel lost detecting. */
343 /* There is a delay when hardware detecting VGA connection, VGA_HOTPLUG_DELAY */
344 /* is workable. If you periodically detect hotplug, you can specify the delay */
345 /* to 0. It is not effective for firmware detecting. */
347 /* channel bits to indicate which outputs are connected and */
348 /* whether input lost. */
349 uint8
ch_check_connection(CH703x_DEV_TYPE chip
, int delay
);
350 int32
ch_set_plug_out_power(CH703x_DEV_TYPE chip
, uint8 enable
);
352 /* channel_bits: combined output channel bits */
353 /* 1: power on this output channel */
354 /* 0: power off this output channel */
355 int32
ch_set_channel_power(CH703x_DEV_TYPE chip
, uint8 channel_bits
);
358 /* channel_bits: combined output channel bits */
359 /* 0x00: force chip to enter standby state to save power. */
360 /* other: wake up chip and power on the specified output channel, */
361 /* then you must call ch_set_mode to setup chip again */
362 int32
ch_set_chip_power(CH703x_DEV_TYPE chip
, uint8 channel_bits
);
364 /* dither: 0 - disable; 1 - enable */
365 int32
ch_set_dither(CH703x_DEV_TYPE chip
, uint8 dither
);
368 /* pwm_duty: same as pwm_duty in LVDS_FMT, 0~255 */
369 /* Return: old setting */
370 uint8
ch_set_lvds_brightness(CH703x_DEV_TYPE chip
, uint8 pwm_duty
);
372 #define MCUAUTO_SETMODE 0x40
373 /* currently you can only enable/disable MCU auto set display mode function. */
374 /* auto ouput channel hotplug and input channel lost detection are always */
375 /* enabled. If you enable MCU auto function, when output channel hotplug, */
376 /* MCU will automatically close/display to this output channel. */
378 /* mcuAutoBits: combined bits to enable MCU auto functions */
379 /* Return: old setting */
380 uint8
ch_enable_MCU_AutoFunc(CH703x_DEV_TYPE chip
, uint8 mcuAutoBits
);
382 /* -------- lvds_bypass_mode, add on 2011-11-11 ---------- */
385 /* current: bit 7, 0 - enable, 1 - disable */
386 /* bi7 2..0, 0 ~ 7 set current to */
387 /* 0 - 2.45mA, 1 - 2.8mA, 2 - 3.15mA, 3 - 3.5mA(default) */
388 /* 4 - 3.85mA, 5 - 4.2mA, 6 - 4.55mA, 7 - 4.9mA */
390 /* only set this when the output is lvds bypass mode */
391 /* some settings may cause panel fail to power on */
392 /* Return: old setting */
393 /* uint8 ch_set_lvds_current(CH703x_DEV_TYPE chip, uint8 current); */
396 /* bOn: 0 - Off; 1 - On */
397 /* Return: old setting */
398 uint8
ch_set_lvds_common_voltage(CH703x_DEV_TYPE chip
, uint8 bOn
);
401 void ch_dump_reg(void);
402 void ch_read_reg(unsigned char u8Reg
);
403 void ch_write_reg(unsigned char u8Reg
, unsigned char u8Data
);
404 void hw_set_HPD_MAX(uint8 addr
);
405 void hw_set_inv_clk(uint8 inv
);
406 void hw_set_suspend(void);
407 void hw_set_resume(void);