2 * Copyright 1998-2008 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2008 S3 Graphics, Inc. All Rights Reserved.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public
7 * License as published by the Free Software Foundation;
8 * either version 2, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTIES OR REPRESENTATIONS; without even
12 * the implied warranty of MERCHANTABILITY or FITNESS FOR
13 * A PARTICULAR PURPOSE.See the GNU General Public License
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 static void tmds_register_write(int index, u8 data);
24 static int tmds_register_read(int index);
25 static int tmds_register_read_bytes(int index, u8 *buff, int buff_len);
26 static void dvi_get_panel_size_from_DDCv1(struct tmds_chip_information
27 *tmds_chip, struct tmds_setting_information *tmds_setting);
28 static void dvi_get_panel_size_from_DDCv2(struct tmds_chip_information
29 *tmds_chip, struct tmds_setting_information *tmds_setting);
30 static int viafb_dvi_query_EDID(void);
32 static int check_tmds_chip(int device_id_subaddr, int device_id)
34 if (tmds_register_read(device_id_subaddr) == device_id)
40 void viafb_init_dvi_size(struct tmds_chip_information *tmds_chip,
41 struct tmds_setting_information *tmds_setting)
43 DEBUG_MSG(KERN_INFO "viafb_init_dvi_size()\n");
46 switch (viafb_dvi_query_EDID()) {
48 dvi_get_panel_size_from_DDCv1(tmds_chip, tmds_setting);
51 dvi_get_panel_size_from_DDCv2(tmds_chip, tmds_setting);
54 printk(KERN_WARNING "viafb_init_dvi_size: DVI panel size undetected!\n");
61 int viafb_tmds_trasmitter_identify(void)
63 unsigned char sr2a = 0, sr1e = 0, sr3e = 0;
65 /* Turn on ouputting pad */
66 switch (viaparinfo->chip_info->gfx_chip_name) {
67 case UNICHROME_K8M890:
68 /*=* DFP Low Pad on *=*/
69 sr2a = viafb_read_reg(VIASR, SR2A);
70 viafb_write_reg_mask(SR2A, VIASR, 0x03, BIT0 + BIT1);
73 case UNICHROME_P4M900:
74 case UNICHROME_P4M890:
76 sr2a = viafb_read_reg(VIASR, SR2A);
77 viafb_write_reg_mask(SR2A, VIASR, 0x03, BIT0 + BIT1);
79 sr1e = viafb_read_reg(VIASR, SR1E);
80 viafb_write_reg_mask(SR1E, VIASR, 0xC0, BIT6 + BIT7);
84 /* DVP0/DVP1 Pad on */
85 sr1e = viafb_read_reg(VIASR, SR1E);
86 viafb_write_reg_mask(SR1E, VIASR, 0xF0, BIT4 +
88 /* SR3E[1]Multi-function selection:
89 0 = Emulate I2C and DDC bus by GPIO2/3/4. */
90 sr3e = viafb_read_reg(VIASR, SR3E);
91 viafb_write_reg_mask(SR3E, VIASR, 0x0, BIT5);
95 /* Check for VT1632: */
96 viaparinfo->chip_info->tmds_chip_info.tmds_chip_name = VT1632_TMDS;
97 viaparinfo->chip_info->
98 tmds_chip_info.tmds_chip_slave_addr = VT1632_TMDS_I2C_ADDR;
99 viaparinfo->chip_info->tmds_chip_info.i2c_port = VIA_I2C_ADAP_31;
100 if (check_tmds_chip(VT1632_DEVICE_ID_REG, VT1632_DEVICE_ID) != FAIL) {
102 * Currently only support 12bits,dual edge,add 24bits mode later
104 tmds_register_write(0x08, 0x3b);
106 DEBUG_MSG(KERN_INFO "\n VT1632 TMDS ! \n");
107 DEBUG_MSG(KERN_INFO "\n %2d",
108 viaparinfo->chip_info->tmds_chip_info.tmds_chip_name);
109 DEBUG_MSG(KERN_INFO "\n %2d",
110 viaparinfo->chip_info->tmds_chip_info.i2c_port);
113 viaparinfo->chip_info->tmds_chip_info.i2c_port = VIA_I2C_ADAP_2C;
114 if (check_tmds_chip(VT1632_DEVICE_ID_REG, VT1632_DEVICE_ID)
116 tmds_register_write(0x08, 0x3b);
117 DEBUG_MSG(KERN_INFO "\n VT1632 TMDS ! \n");
118 DEBUG_MSG(KERN_INFO "\n %2d",
119 viaparinfo->chip_info->
120 tmds_chip_info.tmds_chip_name);
121 DEBUG_MSG(KERN_INFO "\n %2d",
122 viaparinfo->chip_info->
123 tmds_chip_info.i2c_port);
128 viaparinfo->chip_info->tmds_chip_info.tmds_chip_name = INTEGRATED_TMDS;
130 if ((viaparinfo->chip_info->gfx_chip_name == UNICHROME_CX700) &&
131 ((viafb_display_hardware_layout == HW_LAYOUT_DVI_ONLY) ||
132 (viafb_display_hardware_layout == HW_LAYOUT_LCD_DVI))) {
133 DEBUG_MSG(KERN_INFO "\n Integrated TMDS ! \n");
137 switch (viaparinfo->chip_info->gfx_chip_name) {
138 case UNICHROME_K8M890:
139 viafb_write_reg(SR2A, VIASR, sr2a);
142 case UNICHROME_P4M900:
143 case UNICHROME_P4M890:
144 viafb_write_reg(SR2A, VIASR, sr2a);
145 viafb_write_reg(SR1E, VIASR, sr1e);
149 viafb_write_reg(SR1E, VIASR, sr1e);
150 viafb_write_reg(SR3E, VIASR, sr3e);
154 viaparinfo->chip_info->
155 tmds_chip_info.tmds_chip_name = NON_TMDS_TRANSMITTER;
156 viaparinfo->chip_info->tmds_chip_info.
157 tmds_chip_slave_addr = VT1632_TMDS_I2C_ADDR;
161 static void tmds_register_write(int index, u8 data)
163 viafb_i2c_writebyte(viaparinfo->chip_info->tmds_chip_info.i2c_port,
164 viaparinfo->chip_info->tmds_chip_info.tmds_chip_slave_addr,
168 static int tmds_register_read(int index)
172 viafb_i2c_readbyte(viaparinfo->chip_info->tmds_chip_info.i2c_port,
173 (u8) viaparinfo->chip_info->tmds_chip_info.tmds_chip_slave_addr,
178 static int tmds_register_read_bytes(int index, u8 *buff, int buff_len)
180 viafb_i2c_readbytes(viaparinfo->chip_info->tmds_chip_info.i2c_port,
181 (u8) viaparinfo->chip_info->tmds_chip_info.tmds_chip_slave_addr,
182 (u8) index, buff, buff_len);
187 void viafb_dvi_set_mode(struct VideoModeTable *mode, int mode_bpp,
190 struct VideoModeTable *rb_mode;
191 struct crt_mode_table *pDviTiming;
192 unsigned long desirePixelClock, maxPixelClock;
193 pDviTiming = mode->crtc;
194 desirePixelClock = pDviTiming->clk / 1000000;
195 maxPixelClock = (unsigned long)viaparinfo->
196 tmds_setting_info->max_pixel_clock;
198 DEBUG_MSG(KERN_INFO "\nDVI_set_mode!!\n");
200 if ((maxPixelClock != 0) && (desirePixelClock > maxPixelClock)) {
201 rb_mode = viafb_get_rb_mode(mode->crtc[0].crtc.hor_addr,
202 mode->crtc[0].crtc.ver_addr);
205 pDviTiming = rb_mode->crtc;
208 viafb_fill_crtc_timing(pDviTiming, mode, mode_bpp / 8, set_iga);
209 viafb_set_output_path(DEVICE_DVI, set_iga,
210 viaparinfo->chip_info->tmds_chip_info.output_interface);
213 /* Sense DVI Connector */
214 int viafb_dvi_sense(void)
216 u8 RegSR1E = 0, RegSR3E = 0, RegCR6B = 0, RegCR91 = 0,
217 RegCR93 = 0, RegCR9B = 0, data;
220 DEBUG_MSG(KERN_INFO "viafb_dvi_sense!!\n");
222 if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CLE266) {
224 RegSR1E = viafb_read_reg(VIASR, SR1E);
225 viafb_write_reg(SR1E, VIASR, RegSR1E | 0x30);
227 /* CR6B[0]VCK Input Selection: 1 = External clock. */
228 RegCR6B = viafb_read_reg(VIACR, CR6B);
229 viafb_write_reg(CR6B, VIACR, RegCR6B | 0x08);
231 /* CR91[4] VDD On [3] Data On [2] VEE On [1] Back Light Off
232 [0] Software Control Power Sequence */
233 RegCR91 = viafb_read_reg(VIACR, CR91);
234 viafb_write_reg(CR91, VIACR, 0x1D);
236 /* CR93[7] DI1 Data Source Selection: 1 = DSP2.
237 CR93[5] DI1 Clock Source: 1 = internal.
238 CR93[4] DI1 Clock Polarity.
239 CR93[3:1] DI1 Clock Adjust. CR93[0] DI1 enable */
240 RegCR93 = viafb_read_reg(VIACR, CR93);
241 viafb_write_reg(CR93, VIACR, 0x01);
243 /* DVP0/DVP1 Pad on */
244 RegSR1E = viafb_read_reg(VIASR, SR1E);
245 viafb_write_reg(SR1E, VIASR, RegSR1E | 0xF0);
247 /* SR3E[1]Multi-function selection:
248 0 = Emulate I2C and DDC bus by GPIO2/3/4. */
249 RegSR3E = viafb_read_reg(VIASR, SR3E);
250 viafb_write_reg(SR3E, VIASR, RegSR3E & (~0x20));
252 /* CR91[4] VDD On [3] Data On [2] VEE On [1] Back Light Off
253 [0] Software Control Power Sequence */
254 RegCR91 = viafb_read_reg(VIACR, CR91);
255 viafb_write_reg(CR91, VIACR, 0x1D);
257 /*CR9B[4] DVP1 Data Source Selection: 1 = From secondary
258 display.CR9B[2:0] DVP1 Clock Adjust */
259 RegCR9B = viafb_read_reg(VIACR, CR9B);
260 viafb_write_reg(CR9B, VIACR, 0x01);
263 data = (u8) tmds_register_read(0x09);
268 if (viafb_dvi_query_EDID())
273 viafb_write_reg(SR1E, VIASR, RegSR1E);
274 viafb_write_reg(CR91, VIACR, RegCR91);
275 if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CLE266) {
276 viafb_write_reg(CR6B, VIACR, RegCR6B);
277 viafb_write_reg(CR93, VIACR, RegCR93);
279 viafb_write_reg(SR3E, VIASR, RegSR3E);
280 viafb_write_reg(CR9B, VIACR, RegCR9B);
286 /* Query Flat Panel's EDID Table Version Through DVI Connector */
287 static int viafb_dvi_query_EDID(void)
292 DEBUG_MSG(KERN_INFO "viafb_dvi_query_EDID!!\n");
294 restore = viaparinfo->chip_info->tmds_chip_info.tmds_chip_slave_addr;
295 viaparinfo->chip_info->tmds_chip_info.tmds_chip_slave_addr = 0xA0;
297 data0 = (u8) tmds_register_read(0x00);
298 data1 = (u8) tmds_register_read(0x01);
299 if ((data0 == 0) && (data1 == 0xFF)) {
300 viaparinfo->chip_info->
301 tmds_chip_info.tmds_chip_slave_addr = restore;
302 return EDID_VERSION_1; /* Found EDID1 Table */
305 data0 = (u8) tmds_register_read(0x00);
306 viaparinfo->chip_info->tmds_chip_info.tmds_chip_slave_addr = restore;
308 return EDID_VERSION_2; /* Found EDID2 Table */
313 /* Get Panel Size Using EDID1 Table */
314 static void dvi_get_panel_size_from_DDCv1(struct tmds_chip_information
315 *tmds_chip, struct tmds_setting_information *tmds_setting)
317 int i, max_h = 0, tmp, restore;
319 unsigned char EDID_DATA[18];
321 DEBUG_MSG(KERN_INFO "\n dvi_get_panel_size_from_DDCv1 \n");
323 restore = tmds_chip->tmds_chip_slave_addr;
324 tmds_chip->tmds_chip_slave_addr = 0xA0;
326 rData = tmds_register_read(0x23);
334 rData = tmds_register_read(0x24);
342 for (i = 0x25; i < 0x6D; i++) {
352 rData = tmds_register_read(i);
355 /* data = (data + 31) * 8 */
356 tmp = (rData + 31) << 3;
365 tmds_register_read_bytes(i, EDID_DATA, 10);
366 if (!(EDID_DATA[0] || EDID_DATA[1])) {
367 /* The first two byte must be zero. */
368 if (EDID_DATA[3] == 0xFD) {
369 /* To get max pixel clock. */
370 tmds_setting->max_pixel_clock =
381 tmds_setting->max_hres = max_h;
384 tmds_setting->max_vres = 480;
387 tmds_setting->max_vres = 600;
390 tmds_setting->max_vres = 768;
393 tmds_setting->max_vres = 1024;
396 tmds_setting->max_vres = 1050;
399 tmds_setting->max_vres = 1050;
402 tmds_setting->max_vres = 1200;
405 tmds_setting->max_vres = 1080;
408 DEBUG_MSG(KERN_INFO "Unknown panel size max resolution = %d ! "
409 "set default panel size.\n", max_h);
413 DEBUG_MSG(KERN_INFO "DVI max pixelclock = %d\n",
414 tmds_setting->max_pixel_clock);
415 tmds_chip->tmds_chip_slave_addr = restore;
418 /* Get Panel Size Using EDID2 Table */
419 static void dvi_get_panel_size_from_DDCv2(struct tmds_chip_information
420 *tmds_chip, struct tmds_setting_information *tmds_setting)
423 unsigned char R_Buffer[2];
425 DEBUG_MSG(KERN_INFO "\n dvi_get_panel_size_from_DDCv2 \n");
427 restore = tmds_chip->tmds_chip_slave_addr;
428 tmds_chip->tmds_chip_slave_addr = 0xA2;
430 /* Horizontal: 0x76, 0x77 */
431 tmds_register_read_bytes(0x76, R_Buffer, 2);
432 tmds_setting->max_hres = R_Buffer[0] + (R_Buffer[1] << 8);
434 switch (tmds_setting->max_hres) {
436 tmds_setting->max_vres = 480;
439 tmds_setting->max_vres = 600;
442 tmds_setting->max_vres = 768;
445 tmds_setting->max_vres = 1024;
448 tmds_setting->max_vres = 1050;
451 tmds_setting->max_vres = 1050;
454 tmds_setting->max_vres = 1200;
457 DEBUG_MSG(KERN_INFO "Unknown panel size max resolution = %d! "
458 "set default panel size.\n", tmds_setting->max_hres);
462 tmds_chip->tmds_chip_slave_addr = restore;
465 /* If Disable DVI, turn off pad */
466 void viafb_dvi_disable(void)
468 if (viaparinfo->chip_info->
469 tmds_chip_info.output_interface == INTERFACE_DVP0)
470 viafb_write_reg(SR1E, VIASR,
471 viafb_read_reg(VIASR, SR1E) & (~0xC0));
473 if (viaparinfo->chip_info->
474 tmds_chip_info.output_interface == INTERFACE_DVP1)
475 viafb_write_reg(SR1E, VIASR,
476 viafb_read_reg(VIASR, SR1E) & (~0x30));
478 if (viaparinfo->chip_info->
479 tmds_chip_info.output_interface == INTERFACE_DFP_HIGH)
480 viafb_write_reg(SR2A, VIASR,
481 viafb_read_reg(VIASR, SR2A) & (~0x0C));
483 if (viaparinfo->chip_info->
484 tmds_chip_info.output_interface == INTERFACE_DFP_LOW)
485 viafb_write_reg(SR2A, VIASR,
486 viafb_read_reg(VIASR, SR2A) & (~0x03));
488 if (viaparinfo->chip_info->
489 tmds_chip_info.output_interface == INTERFACE_TMDS)
490 /* Turn off TMDS power. */
491 viafb_write_reg(CRD2, VIACR,
492 viafb_read_reg(VIACR, CRD2) | 0x08);
495 /* If Enable DVI, turn off pad */
496 void viafb_dvi_enable(void)
500 if (viaparinfo->chip_info->
501 tmds_chip_info.output_interface == INTERFACE_DVP0) {
502 viafb_write_reg(SR1E, VIASR,
503 viafb_read_reg(VIASR, SR1E) | 0xC0);
504 if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CLE266)
505 tmds_register_write(0x88, 0x3b);
507 /*clear CR91[5] to direct on display period
508 in the secondary diplay path */
509 viafb_write_reg(CR91, VIACR,
510 viafb_read_reg(VIACR, CR91) & 0xDF);
513 if (viaparinfo->chip_info->
514 tmds_chip_info.output_interface == INTERFACE_DVP1) {
515 viafb_write_reg(SR1E, VIASR,
516 viafb_read_reg(VIASR, SR1E) | 0x30);
518 /*fix dvi cann't be enabled with MB VT5718C4 - Al Zhang */
519 if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CLE266) {
520 tmds_register_write(0x88, 0x3b);
522 /*clear CR91[5] to direct on display period
523 in the secondary diplay path */
524 viafb_write_reg(CR91, VIACR,
525 viafb_read_reg(VIACR, CR91) & 0xDF);
528 /*fix DVI cannot enable on EPIA-M board */
529 if (viafb_platform_epia_dvi == 1) {
530 viafb_write_reg_mask(CR91, VIACR, 0x1f, 0x1f);
531 viafb_write_reg_mask(CR88, VIACR, 0x00, BIT6 + BIT0);
532 if (viafb_bus_width == 24) {
533 if (viafb_device_lcd_dualedge == 1)
537 viafb_i2c_writebyte(viaparinfo->chip_info->
538 tmds_chip_info.i2c_port,
539 viaparinfo->chip_info->
540 tmds_chip_info.tmds_chip_slave_addr,
546 if (viaparinfo->chip_info->
547 tmds_chip_info.output_interface == INTERFACE_DFP_HIGH) {
548 viafb_write_reg(SR2A, VIASR,
549 viafb_read_reg(VIASR, SR2A) | 0x0C);
550 viafb_write_reg(CR91, VIACR,
551 viafb_read_reg(VIACR, CR91) & 0xDF);
554 if (viaparinfo->chip_info->
555 tmds_chip_info.output_interface == INTERFACE_DFP_LOW) {
556 viafb_write_reg(SR2A, VIASR,
557 viafb_read_reg(VIASR, SR2A) | 0x03);
558 viafb_write_reg(CR91, VIACR,
559 viafb_read_reg(VIACR, CR91) & 0xDF);
561 if (viaparinfo->chip_info->
562 tmds_chip_info.output_interface == INTERFACE_TMDS) {
563 /* Turn on Display period in the panel path. */
564 viafb_write_reg_mask(CR91, VIACR, 0, BIT7);
566 /* Turn on TMDS power. */
567 viafb_write_reg_mask(CRD2, VIACR, 0, BIT3);