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.
21 #include <linux/via-core.h>
22 #include <linux/via_i2c.h>
25 #define viafb_compact_res(x, y) (((x)<<16)|(y))
27 /* CLE266 Software Power Sequence */
28 /* {Mask}, {Data}, {Delay} */
29 static const int PowerSequenceOn
[3][3] = {
30 {0x10, 0x08, 0x06}, {0x10, 0x08, 0x06}, {0x19, 0x1FE, 0x01}
32 static const int PowerSequenceOff
[3][3] = {
33 {0x06, 0x08, 0x10}, {0x00, 0x00, 0x00}, {0xD2, 0x19, 0x01}
36 static struct _lcd_scaling_factor lcd_scaling_factor
= {
37 /* LCD Horizontal Scaling Factor Register */
38 {LCD_HOR_SCALING_FACTOR_REG_NUM
,
39 {{CR9F
, 0, 1}, {CR77
, 0, 7}, {CR79
, 4, 5} } },
40 /* LCD Vertical Scaling Factor Register */
41 {LCD_VER_SCALING_FACTOR_REG_NUM
,
42 {{CR79
, 3, 3}, {CR78
, 0, 7}, {CR79
, 6, 7} } }
44 static struct _lcd_scaling_factor lcd_scaling_factor_CLE
= {
45 /* LCD Horizontal Scaling Factor Register */
46 {LCD_HOR_SCALING_FACTOR_REG_NUM_CLE
, {{CR77
, 0, 7}, {CR79
, 4, 5} } },
47 /* LCD Vertical Scaling Factor Register */
48 {LCD_VER_SCALING_FACTOR_REG_NUM_CLE
, {{CR78
, 0, 7}, {CR79
, 6, 7} } }
51 static int check_lvds_chip(int device_id_subaddr
, int device_id
);
52 static bool lvds_identify_integratedlvds(void);
53 static void __devinit
fp_id_to_vindex(int panel_id
);
54 static int lvds_register_read(int index
);
55 static void load_lcd_scaling(int set_hres
, int set_vres
, int panel_hres
,
57 static void via_pitch_alignment_patch_lcd(
58 struct lvds_setting_information
*plvds_setting_info
,
59 struct lvds_chip_information
61 static void lcd_patch_skew_dvp0(struct lvds_setting_information
63 struct lvds_chip_information
*plvds_chip_info
);
64 static void lcd_patch_skew_dvp1(struct lvds_setting_information
66 struct lvds_chip_information
*plvds_chip_info
);
67 static void lcd_patch_skew(struct lvds_setting_information
68 *plvds_setting_info
, struct lvds_chip_information
*plvds_chip_info
);
70 static void integrated_lvds_disable(struct lvds_setting_information
72 struct lvds_chip_information
*plvds_chip_info
);
73 static void integrated_lvds_enable(struct lvds_setting_information
75 struct lvds_chip_information
*plvds_chip_info
);
76 static void lcd_powersequence_off(void);
77 static void lcd_powersequence_on(void);
78 static void fill_lcd_format(void);
79 static void check_diport_of_integrated_lvds(
80 struct lvds_chip_information
*plvds_chip_info
,
81 struct lvds_setting_information
83 static struct display_timing
lcd_centering_timging(struct display_timing
85 struct display_timing panel_crt_reg
);
87 static int check_lvds_chip(int device_id_subaddr
, int device_id
)
89 if (lvds_register_read(device_id_subaddr
) == device_id
)
95 void __devinit
viafb_init_lcd_size(void)
97 DEBUG_MSG(KERN_INFO
"viafb_init_lcd_size()\n");
99 fp_id_to_vindex(viafb_lcd_panel_id
);
100 viaparinfo
->lvds_setting_info2
->lcd_panel_hres
=
101 viaparinfo
->lvds_setting_info
->lcd_panel_hres
;
102 viaparinfo
->lvds_setting_info2
->lcd_panel_vres
=
103 viaparinfo
->lvds_setting_info
->lcd_panel_vres
;
104 viaparinfo
->lvds_setting_info2
->device_lcd_dualedge
=
105 viaparinfo
->lvds_setting_info
->device_lcd_dualedge
;
106 viaparinfo
->lvds_setting_info2
->LCDDithering
=
107 viaparinfo
->lvds_setting_info
->LCDDithering
;
110 static bool lvds_identify_integratedlvds(void)
112 if (viafb_display_hardware_layout
== HW_LAYOUT_LCD_EXTERNAL_LCD2
) {
113 /* Two dual channel LCD (Internal LVDS + External LVDS): */
114 /* If we have an external LVDS, such as VT1636, we should
115 have its chip ID already. */
116 if (viaparinfo
->chip_info
->lvds_chip_info
.lvds_chip_name
) {
117 viaparinfo
->chip_info
->lvds_chip_info2
.lvds_chip_name
=
119 DEBUG_MSG(KERN_INFO
"Support two dual channel LVDS! "
120 "(Internal LVDS + External LVDS)\n");
122 viaparinfo
->chip_info
->lvds_chip_info
.lvds_chip_name
=
124 DEBUG_MSG(KERN_INFO
"Not found external LVDS, "
125 "so can't support two dual channel LVDS!\n");
127 } else if (viafb_display_hardware_layout
== HW_LAYOUT_LCD1_LCD2
) {
128 /* Two single channel LCD (Internal LVDS + Internal LVDS): */
129 viaparinfo
->chip_info
->lvds_chip_info
.lvds_chip_name
=
131 viaparinfo
->chip_info
->lvds_chip_info2
.lvds_chip_name
=
133 DEBUG_MSG(KERN_INFO
"Support two single channel LVDS! "
134 "(Internal LVDS + Internal LVDS)\n");
135 } else if (viafb_display_hardware_layout
!= HW_LAYOUT_DVI_ONLY
) {
136 /* If we have found external LVDS, just use it,
137 otherwise, we will use internal LVDS as default. */
138 if (!viaparinfo
->chip_info
->lvds_chip_info
.lvds_chip_name
) {
139 viaparinfo
->chip_info
->lvds_chip_info
.lvds_chip_name
=
141 DEBUG_MSG(KERN_INFO
"Found Integrated LVDS!\n");
144 viaparinfo
->chip_info
->lvds_chip_info
.lvds_chip_name
=
145 NON_LVDS_TRANSMITTER
;
146 DEBUG_MSG(KERN_INFO
"Do not support LVDS!\n");
153 int __devinit
viafb_lvds_trasmitter_identify(void)
155 if (viafb_lvds_identify_vt1636(VIA_PORT_31
)) {
156 viaparinfo
->chip_info
->lvds_chip_info
.i2c_port
= VIA_PORT_31
;
158 "Found VIA VT1636 LVDS on port i2c 0x31\n");
160 if (viafb_lvds_identify_vt1636(VIA_PORT_2C
)) {
161 viaparinfo
->chip_info
->lvds_chip_info
.i2c_port
=
164 "Found VIA VT1636 LVDS on port gpio 0x2c\n");
168 if (viaparinfo
->chip_info
->gfx_chip_name
== UNICHROME_CX700
)
169 lvds_identify_integratedlvds();
171 if (viaparinfo
->chip_info
->lvds_chip_info
.lvds_chip_name
)
173 /* Check for VT1631: */
174 viaparinfo
->chip_info
->lvds_chip_info
.lvds_chip_name
= VT1631_LVDS
;
175 viaparinfo
->chip_info
->lvds_chip_info
.lvds_chip_slave_addr
=
176 VT1631_LVDS_I2C_ADDR
;
178 if (check_lvds_chip(VT1631_DEVICE_ID_REG
, VT1631_DEVICE_ID
) != FAIL
) {
179 DEBUG_MSG(KERN_INFO
"\n VT1631 LVDS ! \n");
180 DEBUG_MSG(KERN_INFO
"\n %2d",
181 viaparinfo
->chip_info
->lvds_chip_info
.lvds_chip_name
);
182 DEBUG_MSG(KERN_INFO
"\n %2d",
183 viaparinfo
->chip_info
->lvds_chip_info
.lvds_chip_name
);
187 viaparinfo
->chip_info
->lvds_chip_info
.lvds_chip_name
=
188 NON_LVDS_TRANSMITTER
;
189 viaparinfo
->chip_info
->lvds_chip_info
.lvds_chip_slave_addr
=
190 VT1631_LVDS_I2C_ADDR
;
194 static void __devinit
fp_id_to_vindex(int panel_id
)
196 DEBUG_MSG(KERN_INFO
"fp_get_panel_id()\n");
198 if (panel_id
> LCD_PANEL_ID_MAXIMUM
)
199 viafb_lcd_panel_id
= panel_id
=
200 viafb_read_reg(VIACR
, CR3F
) & 0x0F;
204 viaparinfo
->lvds_setting_info
->lcd_panel_hres
= 640;
205 viaparinfo
->lvds_setting_info
->lcd_panel_vres
= 480;
206 viaparinfo
->lvds_setting_info
->device_lcd_dualedge
= 0;
207 viaparinfo
->lvds_setting_info
->LCDDithering
= 1;
210 viaparinfo
->lvds_setting_info
->lcd_panel_hres
= 800;
211 viaparinfo
->lvds_setting_info
->lcd_panel_vres
= 600;
212 viaparinfo
->lvds_setting_info
->device_lcd_dualedge
= 0;
213 viaparinfo
->lvds_setting_info
->LCDDithering
= 1;
216 viaparinfo
->lvds_setting_info
->lcd_panel_hres
= 1024;
217 viaparinfo
->lvds_setting_info
->lcd_panel_vres
= 768;
218 viaparinfo
->lvds_setting_info
->device_lcd_dualedge
= 0;
219 viaparinfo
->lvds_setting_info
->LCDDithering
= 1;
222 viaparinfo
->lvds_setting_info
->lcd_panel_hres
= 1280;
223 viaparinfo
->lvds_setting_info
->lcd_panel_vres
= 768;
224 viaparinfo
->lvds_setting_info
->device_lcd_dualedge
= 0;
225 viaparinfo
->lvds_setting_info
->LCDDithering
= 1;
228 viaparinfo
->lvds_setting_info
->lcd_panel_hres
= 1280;
229 viaparinfo
->lvds_setting_info
->lcd_panel_vres
= 1024;
230 viaparinfo
->lvds_setting_info
->device_lcd_dualedge
= 1;
231 viaparinfo
->lvds_setting_info
->LCDDithering
= 1;
234 viaparinfo
->lvds_setting_info
->lcd_panel_hres
= 1400;
235 viaparinfo
->lvds_setting_info
->lcd_panel_vres
= 1050;
236 viaparinfo
->lvds_setting_info
->device_lcd_dualedge
= 1;
237 viaparinfo
->lvds_setting_info
->LCDDithering
= 1;
240 viaparinfo
->lvds_setting_info
->lcd_panel_hres
= 1600;
241 viaparinfo
->lvds_setting_info
->lcd_panel_vres
= 1200;
242 viaparinfo
->lvds_setting_info
->device_lcd_dualedge
= 1;
243 viaparinfo
->lvds_setting_info
->LCDDithering
= 1;
246 viaparinfo
->lvds_setting_info
->lcd_panel_hres
= 800;
247 viaparinfo
->lvds_setting_info
->lcd_panel_vres
= 480;
248 viaparinfo
->lvds_setting_info
->device_lcd_dualedge
= 0;
249 viaparinfo
->lvds_setting_info
->LCDDithering
= 1;
252 viaparinfo
->lvds_setting_info
->lcd_panel_hres
= 1024;
253 viaparinfo
->lvds_setting_info
->lcd_panel_vres
= 768;
254 viaparinfo
->lvds_setting_info
->device_lcd_dualedge
= 1;
255 viaparinfo
->lvds_setting_info
->LCDDithering
= 1;
258 viaparinfo
->lvds_setting_info
->lcd_panel_hres
= 1024;
259 viaparinfo
->lvds_setting_info
->lcd_panel_vres
= 768;
260 viaparinfo
->lvds_setting_info
->device_lcd_dualedge
= 0;
261 viaparinfo
->lvds_setting_info
->LCDDithering
= 0;
264 viaparinfo
->lvds_setting_info
->lcd_panel_hres
= 1024;
265 viaparinfo
->lvds_setting_info
->lcd_panel_vres
= 768;
266 viaparinfo
->lvds_setting_info
->device_lcd_dualedge
= 1;
267 viaparinfo
->lvds_setting_info
->LCDDithering
= 0;
270 viaparinfo
->lvds_setting_info
->lcd_panel_hres
= 1280;
271 viaparinfo
->lvds_setting_info
->lcd_panel_vres
= 768;
272 viaparinfo
->lvds_setting_info
->device_lcd_dualedge
= 0;
273 viaparinfo
->lvds_setting_info
->LCDDithering
= 0;
276 viaparinfo
->lvds_setting_info
->lcd_panel_hres
= 1280;
277 viaparinfo
->lvds_setting_info
->lcd_panel_vres
= 1024;
278 viaparinfo
->lvds_setting_info
->device_lcd_dualedge
= 1;
279 viaparinfo
->lvds_setting_info
->LCDDithering
= 0;
282 viaparinfo
->lvds_setting_info
->lcd_panel_hres
= 1400;
283 viaparinfo
->lvds_setting_info
->lcd_panel_vres
= 1050;
284 viaparinfo
->lvds_setting_info
->device_lcd_dualedge
= 1;
285 viaparinfo
->lvds_setting_info
->LCDDithering
= 0;
288 viaparinfo
->lvds_setting_info
->lcd_panel_hres
= 1600;
289 viaparinfo
->lvds_setting_info
->lcd_panel_vres
= 1200;
290 viaparinfo
->lvds_setting_info
->device_lcd_dualedge
= 1;
291 viaparinfo
->lvds_setting_info
->LCDDithering
= 0;
294 viaparinfo
->lvds_setting_info
->lcd_panel_hres
= 1366;
295 viaparinfo
->lvds_setting_info
->lcd_panel_vres
= 768;
296 viaparinfo
->lvds_setting_info
->device_lcd_dualedge
= 0;
297 viaparinfo
->lvds_setting_info
->LCDDithering
= 0;
300 viaparinfo
->lvds_setting_info
->lcd_panel_hres
= 1024;
301 viaparinfo
->lvds_setting_info
->lcd_panel_vres
= 600;
302 viaparinfo
->lvds_setting_info
->device_lcd_dualedge
= 0;
303 viaparinfo
->lvds_setting_info
->LCDDithering
= 1;
306 viaparinfo
->lvds_setting_info
->lcd_panel_hres
= 1280;
307 viaparinfo
->lvds_setting_info
->lcd_panel_vres
= 768;
308 viaparinfo
->lvds_setting_info
->device_lcd_dualedge
= 1;
309 viaparinfo
->lvds_setting_info
->LCDDithering
= 1;
312 viaparinfo
->lvds_setting_info
->lcd_panel_hres
= 1280;
313 viaparinfo
->lvds_setting_info
->lcd_panel_vres
= 800;
314 viaparinfo
->lvds_setting_info
->device_lcd_dualedge
= 0;
315 viaparinfo
->lvds_setting_info
->LCDDithering
= 1;
318 viaparinfo
->lvds_setting_info
->lcd_panel_hres
= 1360;
319 viaparinfo
->lvds_setting_info
->lcd_panel_vres
= 768;
320 viaparinfo
->lvds_setting_info
->device_lcd_dualedge
= 0;
321 viaparinfo
->lvds_setting_info
->LCDDithering
= 0;
324 viaparinfo
->lvds_setting_info
->lcd_panel_hres
= 1280;
325 viaparinfo
->lvds_setting_info
->lcd_panel_vres
= 768;
326 viaparinfo
->lvds_setting_info
->device_lcd_dualedge
= 1;
327 viaparinfo
->lvds_setting_info
->LCDDithering
= 0;
330 viaparinfo
->lvds_setting_info
->lcd_panel_hres
= 480;
331 viaparinfo
->lvds_setting_info
->lcd_panel_vres
= 640;
332 viaparinfo
->lvds_setting_info
->device_lcd_dualedge
= 0;
333 viaparinfo
->lvds_setting_info
->LCDDithering
= 1;
336 /* OLPC XO-1.5 panel */
337 viaparinfo
->lvds_setting_info
->lcd_panel_hres
= 1200;
338 viaparinfo
->lvds_setting_info
->lcd_panel_vres
= 900;
339 viaparinfo
->lvds_setting_info
->device_lcd_dualedge
= 0;
340 viaparinfo
->lvds_setting_info
->LCDDithering
= 0;
343 viaparinfo
->lvds_setting_info
->lcd_panel_hres
= 800;
344 viaparinfo
->lvds_setting_info
->lcd_panel_vres
= 600;
345 viaparinfo
->lvds_setting_info
->device_lcd_dualedge
= 0;
346 viaparinfo
->lvds_setting_info
->LCDDithering
= 1;
350 static int lvds_register_read(int index
)
354 viafb_i2c_readbyte(VIA_PORT_2C
,
355 (u8
) viaparinfo
->chip_info
->lvds_chip_info
.lvds_chip_slave_addr
,
360 static void load_lcd_scaling(int set_hres
, int set_vres
, int panel_hres
,
364 int viafb_load_reg_num
;
365 struct io_register
*reg
= NULL
;
367 DEBUG_MSG(KERN_INFO
"load_lcd_scaling()!!\n");
369 /* LCD Scaling Enable */
370 viafb_write_reg_mask(CR79
, VIACR
, 0x07, BIT0
+ BIT1
+ BIT2
);
372 /* Check if expansion for horizontal */
373 if (set_hres
< panel_hres
) {
374 /* Load Horizontal Scaling Factor */
375 switch (viaparinfo
->chip_info
->gfx_chip_name
) {
376 case UNICHROME_CLE266
:
379 CLE266_LCD_HOR_SCF_FORMULA(set_hres
, panel_hres
);
381 lcd_scaling_factor_CLE
.lcd_hor_scaling_factor
.
383 reg
= lcd_scaling_factor_CLE
.lcd_hor_scaling_factor
.reg
;
384 viafb_load_reg(reg_value
,
385 viafb_load_reg_num
, reg
, VIACR
);
388 case UNICHROME_PM800
:
389 case UNICHROME_CN700
:
390 case UNICHROME_CX700
:
391 case UNICHROME_K8M890
:
392 case UNICHROME_P4M890
:
393 case UNICHROME_P4M900
:
394 case UNICHROME_CN750
:
395 case UNICHROME_VX800
:
396 case UNICHROME_VX855
:
397 case UNICHROME_VX900
:
399 K800_LCD_HOR_SCF_FORMULA(set_hres
, panel_hres
);
400 /* Horizontal scaling enabled */
401 viafb_write_reg_mask(CRA2
, VIACR
, 0xC0, BIT7
+ BIT6
);
403 lcd_scaling_factor
.lcd_hor_scaling_factor
.reg_num
;
404 reg
= lcd_scaling_factor
.lcd_hor_scaling_factor
.reg
;
405 viafb_load_reg(reg_value
,
406 viafb_load_reg_num
, reg
, VIACR
);
410 DEBUG_MSG(KERN_INFO
"Horizontal Scaling value = %d", reg_value
);
412 /* Horizontal scaling disabled */
413 viafb_write_reg_mask(CRA2
, VIACR
, 0x00, BIT7
);
416 /* Check if expansion for vertical */
417 if (set_vres
< panel_vres
) {
418 /* Load Vertical Scaling Factor */
419 switch (viaparinfo
->chip_info
->gfx_chip_name
) {
420 case UNICHROME_CLE266
:
423 CLE266_LCD_VER_SCF_FORMULA(set_vres
, panel_vres
);
425 lcd_scaling_factor_CLE
.lcd_ver_scaling_factor
.
427 reg
= lcd_scaling_factor_CLE
.lcd_ver_scaling_factor
.reg
;
428 viafb_load_reg(reg_value
,
429 viafb_load_reg_num
, reg
, VIACR
);
432 case UNICHROME_PM800
:
433 case UNICHROME_CN700
:
434 case UNICHROME_CX700
:
435 case UNICHROME_K8M890
:
436 case UNICHROME_P4M890
:
437 case UNICHROME_P4M900
:
438 case UNICHROME_CN750
:
439 case UNICHROME_VX800
:
440 case UNICHROME_VX855
:
441 case UNICHROME_VX900
:
443 K800_LCD_VER_SCF_FORMULA(set_vres
, panel_vres
);
444 /* Vertical scaling enabled */
445 viafb_write_reg_mask(CRA2
, VIACR
, 0x08, BIT3
);
447 lcd_scaling_factor
.lcd_ver_scaling_factor
.reg_num
;
448 reg
= lcd_scaling_factor
.lcd_ver_scaling_factor
.reg
;
449 viafb_load_reg(reg_value
,
450 viafb_load_reg_num
, reg
, VIACR
);
454 DEBUG_MSG(KERN_INFO
"Vertical Scaling value = %d", reg_value
);
456 /* Vertical scaling disabled */
457 viafb_write_reg_mask(CRA2
, VIACR
, 0x00, BIT3
);
461 static void via_pitch_alignment_patch_lcd(
462 struct lvds_setting_information
*plvds_setting_info
,
463 struct lvds_chip_information
466 unsigned char cr13
, cr35
, cr65
, cr66
, cr67
;
467 unsigned long dwScreenPitch
= 0;
468 unsigned long dwPitch
;
470 dwPitch
= plvds_setting_info
->h_active
* (plvds_setting_info
->bpp
>> 3);
471 if (dwPitch
& 0x1F) {
472 dwScreenPitch
= ((dwPitch
+ 31) & ~31) >> 3;
473 if (plvds_setting_info
->iga_path
== IGA2
) {
474 if (plvds_setting_info
->bpp
> 8) {
475 cr66
= (unsigned char)(dwScreenPitch
& 0xFF);
476 viafb_write_reg(CR66
, VIACR
, cr66
);
477 cr67
= viafb_read_reg(VIACR
, CR67
) & 0xFC;
480 char)((dwScreenPitch
& 0x300) >> 8);
481 viafb_write_reg(CR67
, VIACR
, cr67
);
485 cr67
= viafb_read_reg(VIACR
, CR67
) & 0xF3;
486 cr67
|= (unsigned char)((dwScreenPitch
& 0x600) >> 7);
487 viafb_write_reg(CR67
, VIACR
, cr67
);
488 cr65
= (unsigned char)((dwScreenPitch
>> 1) & 0xFF);
490 viafb_write_reg(CR65
, VIACR
, cr65
);
492 if (plvds_setting_info
->bpp
> 8) {
493 cr13
= (unsigned char)(dwScreenPitch
& 0xFF);
494 viafb_write_reg(CR13
, VIACR
, cr13
);
495 cr35
= viafb_read_reg(VIACR
, CR35
) & 0x1F;
498 char)((dwScreenPitch
& 0x700) >> 3);
499 viafb_write_reg(CR35
, VIACR
, cr35
);
504 static void lcd_patch_skew_dvp0(struct lvds_setting_information
506 struct lvds_chip_information
*plvds_chip_info
)
508 if (VT1636_LVDS
== plvds_chip_info
->lvds_chip_name
) {
509 switch (viaparinfo
->chip_info
->gfx_chip_name
) {
510 case UNICHROME_P4M900
:
511 viafb_vt1636_patch_skew_on_vt3364(plvds_setting_info
,
514 case UNICHROME_P4M890
:
515 viafb_vt1636_patch_skew_on_vt3327(plvds_setting_info
,
521 static void lcd_patch_skew_dvp1(struct lvds_setting_information
523 struct lvds_chip_information
*plvds_chip_info
)
525 if (VT1636_LVDS
== plvds_chip_info
->lvds_chip_name
) {
526 switch (viaparinfo
->chip_info
->gfx_chip_name
) {
527 case UNICHROME_CX700
:
528 viafb_vt1636_patch_skew_on_vt3324(plvds_setting_info
,
534 static void lcd_patch_skew(struct lvds_setting_information
535 *plvds_setting_info
, struct lvds_chip_information
*plvds_chip_info
)
537 DEBUG_MSG(KERN_INFO
"lcd_patch_skew\n");
538 switch (plvds_chip_info
->output_interface
) {
540 lcd_patch_skew_dvp0(plvds_setting_info
, plvds_chip_info
);
543 lcd_patch_skew_dvp1(plvds_setting_info
, plvds_chip_info
);
545 case INTERFACE_DFP_LOW
:
546 if (UNICHROME_P4M900
== viaparinfo
->chip_info
->gfx_chip_name
) {
547 viafb_write_reg_mask(CR99
, VIACR
, 0x08,
548 BIT0
+ BIT1
+ BIT2
+ BIT3
);
555 void viafb_lcd_set_mode(struct crt_mode_table
*mode_crt_table
,
556 struct lvds_setting_information
*plvds_setting_info
,
557 struct lvds_chip_information
*plvds_chip_info
)
559 int set_iga
= plvds_setting_info
->iga_path
;
560 int mode_bpp
= plvds_setting_info
->bpp
;
561 int set_hres
= plvds_setting_info
->h_active
;
562 int set_vres
= plvds_setting_info
->v_active
;
563 int panel_hres
= plvds_setting_info
->lcd_panel_hres
;
564 int panel_vres
= plvds_setting_info
->lcd_panel_vres
;
566 struct display_timing mode_crt_reg
, panel_crt_reg
;
567 struct crt_mode_table
*panel_crt_table
= NULL
;
568 struct VideoModeTable
*vmode_tbl
= viafb_get_mode(panel_hres
,
571 DEBUG_MSG(KERN_INFO
"viafb_lcd_set_mode!!\n");
573 mode_crt_reg
= mode_crt_table
->crtc
;
574 /* Get panel table Pointer */
575 panel_crt_table
= vmode_tbl
->crtc
;
576 panel_crt_reg
= panel_crt_table
->crtc
;
577 DEBUG_MSG(KERN_INFO
"bellow viafb_lcd_set_mode!!\n");
578 if (VT1636_LVDS
== plvds_chip_info
->lvds_chip_name
)
579 viafb_init_lvds_vt1636(plvds_setting_info
, plvds_chip_info
);
580 clock
= panel_crt_reg
.hor_total
* panel_crt_reg
.ver_total
581 * panel_crt_table
->refresh_rate
;
582 plvds_setting_info
->vclk
= clock
;
583 if (set_iga
== IGA1
) {
584 /* IGA1 doesn't have LCD scaling, so set it as centering. */
585 viafb_load_crtc_timing(lcd_centering_timging
586 (mode_crt_reg
, panel_crt_reg
), IGA1
);
589 if (plvds_setting_info
->display_method
== LCD_EXPANDSION
590 && (set_hres
< panel_hres
|| set_vres
< panel_vres
)) {
591 /* expansion timing IGA2 loaded panel set timing*/
592 viafb_load_crtc_timing(panel_crt_reg
, IGA2
);
593 DEBUG_MSG(KERN_INFO
"viafb_load_crtc_timing!!\n");
594 load_lcd_scaling(set_hres
, set_vres
, panel_hres
,
596 DEBUG_MSG(KERN_INFO
"load_lcd_scaling!!\n");
597 } else { /* Centering */
598 /* centering timing IGA2 always loaded panel
599 and mode releative timing */
600 viafb_load_crtc_timing(lcd_centering_timging
601 (mode_crt_reg
, panel_crt_reg
), IGA2
);
602 viafb_write_reg_mask(CR79
, VIACR
, 0x00,
604 /* LCD scaling disabled */
608 /* Fetch count for IGA2 only */
609 viafb_load_fetch_count_reg(set_hres
, mode_bpp
/ 8, set_iga
);
611 if ((viaparinfo
->chip_info
->gfx_chip_name
!= UNICHROME_CLE266
)
612 && (viaparinfo
->chip_info
->gfx_chip_name
!= UNICHROME_K400
))
613 viafb_load_FIFO_reg(set_iga
, set_hres
, set_vres
);
617 pll_D_N
= viafb_get_clk_value(clock
);
618 DEBUG_MSG(KERN_INFO
"PLL=0x%x", pll_D_N
);
619 viafb_set_vclock(pll_D_N
, set_iga
);
620 lcd_patch_skew(plvds_setting_info
, plvds_chip_info
);
622 /* If K8M800, enable LCD Prefetch Mode. */
623 if ((viaparinfo
->chip_info
->gfx_chip_name
== UNICHROME_K800
)
624 || (UNICHROME_K8M890
== viaparinfo
->chip_info
->gfx_chip_name
))
625 viafb_write_reg_mask(CR6A
, VIACR
, 0x01, BIT0
);
627 /* Patch for non 32bit alignment mode */
628 via_pitch_alignment_patch_lcd(plvds_setting_info
, plvds_chip_info
);
631 static void integrated_lvds_disable(struct lvds_setting_information
633 struct lvds_chip_information
*plvds_chip_info
)
635 bool turn_off_first_powersequence
= false;
636 bool turn_off_second_powersequence
= false;
637 if (INTERFACE_LVDS0LVDS1
== plvds_chip_info
->output_interface
)
638 turn_off_first_powersequence
= true;
639 if (INTERFACE_LVDS0
== plvds_chip_info
->output_interface
)
640 turn_off_first_powersequence
= true;
641 if (INTERFACE_LVDS1
== plvds_chip_info
->output_interface
)
642 turn_off_second_powersequence
= true;
643 if (turn_off_second_powersequence
) {
644 /* Use second power sequence control: */
646 /* Turn off power sequence. */
647 viafb_write_reg_mask(CRD4
, VIACR
, 0, BIT1
);
649 /* Turn off back light. */
650 viafb_write_reg_mask(CRD3
, VIACR
, 0xC0, BIT6
+ BIT7
);
652 if (turn_off_first_powersequence
) {
653 /* Use first power sequence control: */
655 /* Turn off power sequence. */
656 viafb_write_reg_mask(CR6A
, VIACR
, 0, BIT3
);
658 /* Turn off back light. */
659 viafb_write_reg_mask(CR91
, VIACR
, 0xC0, BIT6
+ BIT7
);
662 /* Power off LVDS channel. */
663 switch (plvds_chip_info
->output_interface
) {
664 case INTERFACE_LVDS0
:
666 viafb_write_reg_mask(CRD2
, VIACR
, 0x80, BIT7
);
670 case INTERFACE_LVDS1
:
672 viafb_write_reg_mask(CRD2
, VIACR
, 0x40, BIT6
);
676 case INTERFACE_LVDS0LVDS1
:
678 viafb_write_reg_mask(CRD2
, VIACR
, 0xC0, BIT6
+ BIT7
);
684 static void integrated_lvds_enable(struct lvds_setting_information
686 struct lvds_chip_information
*plvds_chip_info
)
688 DEBUG_MSG(KERN_INFO
"integrated_lvds_enable, out_interface:%d\n",
689 plvds_chip_info
->output_interface
);
690 if (plvds_setting_info
->lcd_mode
== LCD_SPWG
)
691 viafb_write_reg_mask(CRD2
, VIACR
, 0x00, BIT0
+ BIT1
);
693 viafb_write_reg_mask(CRD2
, VIACR
, 0x03, BIT0
+ BIT1
);
695 switch (plvds_chip_info
->output_interface
) {
696 case INTERFACE_LVDS0LVDS1
:
697 case INTERFACE_LVDS0
:
698 /* Use first power sequence control: */
699 /* Use hardware control power sequence. */
700 viafb_write_reg_mask(CR91
, VIACR
, 0, BIT0
);
701 /* Turn on back light. */
702 viafb_write_reg_mask(CR91
, VIACR
, 0, BIT6
+ BIT7
);
703 /* Turn on hardware power sequence. */
704 viafb_write_reg_mask(CR6A
, VIACR
, 0x08, BIT3
);
706 case INTERFACE_LVDS1
:
707 /* Use second power sequence control: */
708 /* Use hardware control power sequence. */
709 viafb_write_reg_mask(CRD3
, VIACR
, 0, BIT0
);
710 /* Turn on back light. */
711 viafb_write_reg_mask(CRD3
, VIACR
, 0, BIT6
+ BIT7
);
712 /* Turn on hardware power sequence. */
713 viafb_write_reg_mask(CRD4
, VIACR
, 0x02, BIT1
);
717 /* Power on LVDS channel. */
718 switch (plvds_chip_info
->output_interface
) {
719 case INTERFACE_LVDS0
:
721 viafb_write_reg_mask(CRD2
, VIACR
, 0, BIT7
);
725 case INTERFACE_LVDS1
:
727 viafb_write_reg_mask(CRD2
, VIACR
, 0, BIT6
);
731 case INTERFACE_LVDS0LVDS1
:
733 viafb_write_reg_mask(CRD2
, VIACR
, 0, BIT6
+ BIT7
);
739 void viafb_lcd_disable(void)
742 if (viaparinfo
->chip_info
->gfx_chip_name
== UNICHROME_CLE266
) {
743 lcd_powersequence_off();
745 viafb_write_reg_mask(SR1E
, VIASR
, 0x00, 0x30);
746 } else if (viaparinfo
->chip_info
->gfx_chip_name
== UNICHROME_CX700
) {
748 && (INTEGRATED_LVDS
==
749 viaparinfo
->chip_info
->lvds_chip_info2
.lvds_chip_name
))
750 integrated_lvds_disable(viaparinfo
->lvds_setting_info
,
751 &viaparinfo
->chip_info
->lvds_chip_info2
);
752 if (INTEGRATED_LVDS
==
753 viaparinfo
->chip_info
->lvds_chip_info
.lvds_chip_name
)
754 integrated_lvds_disable(viaparinfo
->lvds_setting_info
,
755 &viaparinfo
->chip_info
->lvds_chip_info
);
756 if (VT1636_LVDS
== viaparinfo
->chip_info
->
757 lvds_chip_info
.lvds_chip_name
)
758 viafb_disable_lvds_vt1636(viaparinfo
->lvds_setting_info
,
759 &viaparinfo
->chip_info
->lvds_chip_info
);
760 } else if (VT1636_LVDS
==
761 viaparinfo
->chip_info
->lvds_chip_info
.lvds_chip_name
) {
762 viafb_disable_lvds_vt1636(viaparinfo
->lvds_setting_info
,
763 &viaparinfo
->chip_info
->lvds_chip_info
);
766 viafb_write_reg_mask(SR3D
, VIASR
, 0x00, 0x20);
767 /* 24 bit DI data paht off */
768 viafb_write_reg_mask(CR91
, VIACR
, 0x80, 0x80);
771 /* Disable expansion bit */
772 viafb_write_reg_mask(CR79
, VIACR
, 0x00, 0x01);
773 /* Simultaneout disabled */
774 viafb_write_reg_mask(CR6B
, VIACR
, 0x00, 0x08);
777 static void set_lcd_output_path(int set_iga
, int output_interface
)
779 switch (output_interface
) {
781 if ((UNICHROME_K8M890
== viaparinfo
->chip_info
->gfx_chip_name
)
782 || (UNICHROME_P4M890
==
783 viaparinfo
->chip_info
->gfx_chip_name
))
784 viafb_write_reg_mask(CR97
, VIACR
, 0x84,
785 BIT7
+ BIT2
+ BIT1
+ BIT0
);
788 case INTERFACE_DFP_HIGH
:
789 case INTERFACE_DFP_LOW
:
791 viafb_write_reg(CR91
, VIACR
, 0x00);
796 void viafb_lcd_enable(void)
798 viafb_write_reg_mask(CR6B
, VIACR
, 0x00, BIT3
);
799 viafb_write_reg_mask(CR6A
, VIACR
, 0x08, BIT3
);
800 set_lcd_output_path(viaparinfo
->lvds_setting_info
->iga_path
,
801 viaparinfo
->chip_info
->lvds_chip_info
.output_interface
);
803 set_lcd_output_path(viaparinfo
->lvds_setting_info2
->iga_path
,
804 viaparinfo
->chip_info
->
805 lvds_chip_info2
.output_interface
);
807 if (viaparinfo
->chip_info
->gfx_chip_name
== UNICHROME_CLE266
) {
809 viafb_write_reg_mask(SR1E
, VIASR
, 0x30, 0x30);
810 lcd_powersequence_on();
811 } else if (viaparinfo
->chip_info
->gfx_chip_name
== UNICHROME_CX700
) {
812 if (viafb_LCD2_ON
&& (INTEGRATED_LVDS
==
813 viaparinfo
->chip_info
->lvds_chip_info2
.lvds_chip_name
))
814 integrated_lvds_enable(viaparinfo
->lvds_setting_info2
, \
815 &viaparinfo
->chip_info
->lvds_chip_info2
);
816 if (INTEGRATED_LVDS
==
817 viaparinfo
->chip_info
->lvds_chip_info
.lvds_chip_name
)
818 integrated_lvds_enable(viaparinfo
->lvds_setting_info
,
819 &viaparinfo
->chip_info
->lvds_chip_info
);
820 if (VT1636_LVDS
== viaparinfo
->chip_info
->
821 lvds_chip_info
.lvds_chip_name
)
822 viafb_enable_lvds_vt1636(viaparinfo
->
823 lvds_setting_info
, &viaparinfo
->chip_info
->
825 } else if (VT1636_LVDS
==
826 viaparinfo
->chip_info
->lvds_chip_info
.lvds_chip_name
) {
827 viafb_enable_lvds_vt1636(viaparinfo
->lvds_setting_info
,
828 &viaparinfo
->chip_info
->lvds_chip_info
);
831 viafb_write_reg_mask(SR3D
, VIASR
, 0x20, 0x20);
832 /* 24 bit DI data paht on */
833 viafb_write_reg_mask(CR91
, VIACR
, 0x00, 0x80);
835 viafb_write_reg_mask(CR6A
, VIACR
, 0x48, 0x48);
839 static void lcd_powersequence_off(void)
843 /* Software control power sequence */
844 viafb_write_reg_mask(CR91
, VIACR
, 0x11, 0x11);
846 for (i
= 0; i
< 3; i
++) {
847 mask
= PowerSequenceOff
[0][i
];
848 data
= PowerSequenceOff
[1][i
] & mask
;
849 viafb_write_reg_mask(CR91
, VIACR
, (u8
) data
, (u8
) mask
);
850 udelay(PowerSequenceOff
[2][i
]);
854 viafb_write_reg_mask(CR6A
, VIACR
, 0x00, 0x08);
857 static void lcd_powersequence_on(void)
861 /* Software control power sequence */
862 viafb_write_reg_mask(CR91
, VIACR
, 0x11, 0x11);
865 viafb_write_reg_mask(CR6A
, VIACR
, 0x08, 0x08);
867 for (i
= 0; i
< 3; i
++) {
868 mask
= PowerSequenceOn
[0][i
];
869 data
= PowerSequenceOn
[1][i
] & mask
;
870 viafb_write_reg_mask(CR91
, VIACR
, (u8
) data
, (u8
) mask
);
871 udelay(PowerSequenceOn
[2][i
]);
877 static void fill_lcd_format(void)
879 u8 bdithering
= 0, bdual
= 0;
881 if (viaparinfo
->lvds_setting_info
->device_lcd_dualedge
)
883 if (viaparinfo
->lvds_setting_info
->LCDDithering
)
885 /* Dual & Dithering */
886 viafb_write_reg_mask(CR88
, VIACR
, (bdithering
| bdual
), BIT4
+ BIT0
);
889 static void check_diport_of_integrated_lvds(
890 struct lvds_chip_information
*plvds_chip_info
,
891 struct lvds_setting_information
894 /* Determine LCD DI Port by hardware layout. */
895 switch (viafb_display_hardware_layout
) {
896 case HW_LAYOUT_LCD_ONLY
:
898 if (plvds_setting_info
->device_lcd_dualedge
) {
899 plvds_chip_info
->output_interface
=
900 INTERFACE_LVDS0LVDS1
;
902 plvds_chip_info
->output_interface
=
909 case HW_LAYOUT_DVI_ONLY
:
911 plvds_chip_info
->output_interface
= INTERFACE_NONE
;
915 case HW_LAYOUT_LCD1_LCD2
:
916 case HW_LAYOUT_LCD_EXTERNAL_LCD2
:
918 plvds_chip_info
->output_interface
=
919 INTERFACE_LVDS0LVDS1
;
923 case HW_LAYOUT_LCD_DVI
:
925 plvds_chip_info
->output_interface
= INTERFACE_LVDS1
;
931 plvds_chip_info
->output_interface
= INTERFACE_LVDS1
;
937 "Display Hardware Layout: 0x%x, LCD DI Port: 0x%x\n",
938 viafb_display_hardware_layout
,
939 plvds_chip_info
->output_interface
);
942 void __devinit
viafb_init_lvds_output_interface(struct lvds_chip_information
944 struct lvds_setting_information
947 if (INTERFACE_NONE
!= plvds_chip_info
->output_interface
) {
948 /*Do nothing, lcd port is specified by module parameter */
952 switch (plvds_chip_info
->lvds_chip_name
) {
955 switch (viaparinfo
->chip_info
->gfx_chip_name
) {
956 case UNICHROME_CX700
:
957 plvds_chip_info
->output_interface
= INTERFACE_DVP1
;
959 case UNICHROME_CN700
:
960 plvds_chip_info
->output_interface
= INTERFACE_DFP_LOW
;
963 plvds_chip_info
->output_interface
= INTERFACE_DVP0
;
968 case INTEGRATED_LVDS
:
969 check_diport_of_integrated_lvds(plvds_chip_info
,
974 switch (viaparinfo
->chip_info
->gfx_chip_name
) {
975 case UNICHROME_K8M890
:
976 case UNICHROME_P4M900
:
977 case UNICHROME_P4M890
:
978 plvds_chip_info
->output_interface
= INTERFACE_DFP_LOW
;
981 plvds_chip_info
->output_interface
= INTERFACE_DFP
;
988 static struct display_timing
lcd_centering_timging(struct display_timing
990 struct display_timing panel_crt_reg
)
992 struct display_timing crt_reg
;
994 crt_reg
.hor_total
= panel_crt_reg
.hor_total
;
995 crt_reg
.hor_addr
= mode_crt_reg
.hor_addr
;
996 crt_reg
.hor_blank_start
=
997 (panel_crt_reg
.hor_addr
- mode_crt_reg
.hor_addr
) / 2 +
999 crt_reg
.hor_blank_end
= panel_crt_reg
.hor_blank_end
;
1000 crt_reg
.hor_sync_start
=
1001 (panel_crt_reg
.hor_sync_start
-
1002 panel_crt_reg
.hor_blank_start
) + crt_reg
.hor_blank_start
;
1003 crt_reg
.hor_sync_end
= panel_crt_reg
.hor_sync_end
;
1005 crt_reg
.ver_total
= panel_crt_reg
.ver_total
;
1006 crt_reg
.ver_addr
= mode_crt_reg
.ver_addr
;
1007 crt_reg
.ver_blank_start
=
1008 (panel_crt_reg
.ver_addr
- mode_crt_reg
.ver_addr
) / 2 +
1010 crt_reg
.ver_blank_end
= panel_crt_reg
.ver_blank_end
;
1011 crt_reg
.ver_sync_start
=
1012 (panel_crt_reg
.ver_sync_start
-
1013 panel_crt_reg
.ver_blank_start
) + crt_reg
.ver_blank_start
;
1014 crt_reg
.ver_sync_end
= panel_crt_reg
.ver_sync_end
;
1019 bool viafb_lcd_get_mobile_state(bool *mobile
)
1021 unsigned char __iomem
*romptr
, *tableptr
, *biosptr
;
1024 const u32 romaddr
= 0x000C0000;
1027 biosptr
= ioremap(romaddr
, 0x10000);
1028 start_pattern
= readw(biosptr
);
1030 /* Compare pattern */
1031 if (start_pattern
== 0xAA55) {
1032 /* Get the start of Table */
1033 /* 0x1B means BIOS offset position */
1034 romptr
= biosptr
+ 0x1B;
1035 tableptr
= biosptr
+ readw(romptr
);
1037 /* Get the start of biosver structure */
1038 /* 18 means BIOS version position. */
1039 romptr
= tableptr
+ 18;
1040 romptr
= biosptr
+ readw(romptr
);
1042 /* The offset should be 44, but the
1043 actual image is less three char. */
1047 core_base
= readb(romptr
);
1049 if (core_base
& 0x8)
1053 /* release memory */