1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright 1998-2008 VIA Technologies, Inc. All Rights Reserved.
4 * Copyright 2001-2008 S3 Graphics, Inc. All Rights Reserved.
7 #include <linux/via-core.h>
8 #include <linux/via_i2c.h>
11 #define viafb_compact_res(x, y) (((x)<<16)|(y))
13 /* CLE266 Software Power Sequence */
14 /* {Mask}, {Data}, {Delay} */
15 static const int PowerSequenceOn
[3][3] = {
16 {0x10, 0x08, 0x06}, {0x10, 0x08, 0x06}, {0x19, 0x1FE, 0x01}
18 static const int PowerSequenceOff
[3][3] = {
19 {0x06, 0x08, 0x10}, {0x00, 0x00, 0x00}, {0xD2, 0x19, 0x01}
22 static struct _lcd_scaling_factor lcd_scaling_factor
= {
23 /* LCD Horizontal Scaling Factor Register */
24 {LCD_HOR_SCALING_FACTOR_REG_NUM
,
25 {{CR9F
, 0, 1}, {CR77
, 0, 7}, {CR79
, 4, 5} } },
26 /* LCD Vertical Scaling Factor Register */
27 {LCD_VER_SCALING_FACTOR_REG_NUM
,
28 {{CR79
, 3, 3}, {CR78
, 0, 7}, {CR79
, 6, 7} } }
30 static struct _lcd_scaling_factor lcd_scaling_factor_CLE
= {
31 /* LCD Horizontal Scaling Factor Register */
32 {LCD_HOR_SCALING_FACTOR_REG_NUM_CLE
, {{CR77
, 0, 7}, {CR79
, 4, 5} } },
33 /* LCD Vertical Scaling Factor Register */
34 {LCD_VER_SCALING_FACTOR_REG_NUM_CLE
, {{CR78
, 0, 7}, {CR79
, 6, 7} } }
37 static bool lvds_identify_integratedlvds(void);
38 static void fp_id_to_vindex(int panel_id
);
39 static int lvds_register_read(int index
);
40 static void load_lcd_scaling(int set_hres
, int set_vres
, int panel_hres
,
42 static void lcd_patch_skew_dvp0(struct lvds_setting_information
44 struct lvds_chip_information
*plvds_chip_info
);
45 static void lcd_patch_skew_dvp1(struct lvds_setting_information
47 struct lvds_chip_information
*plvds_chip_info
);
48 static void lcd_patch_skew(struct lvds_setting_information
49 *plvds_setting_info
, struct lvds_chip_information
*plvds_chip_info
);
51 static void integrated_lvds_disable(struct lvds_setting_information
53 struct lvds_chip_information
*plvds_chip_info
);
54 static void integrated_lvds_enable(struct lvds_setting_information
56 struct lvds_chip_information
*plvds_chip_info
);
57 static void lcd_powersequence_off(void);
58 static void lcd_powersequence_on(void);
59 static void fill_lcd_format(void);
60 static void check_diport_of_integrated_lvds(
61 struct lvds_chip_information
*plvds_chip_info
,
62 struct lvds_setting_information
65 static inline bool check_lvds_chip(int device_id_subaddr
, int device_id
)
67 return lvds_register_read(device_id_subaddr
) == device_id
;
70 void viafb_init_lcd_size(void)
72 DEBUG_MSG(KERN_INFO
"viafb_init_lcd_size()\n");
74 fp_id_to_vindex(viafb_lcd_panel_id
);
75 viaparinfo
->lvds_setting_info2
->lcd_panel_hres
=
76 viaparinfo
->lvds_setting_info
->lcd_panel_hres
;
77 viaparinfo
->lvds_setting_info2
->lcd_panel_vres
=
78 viaparinfo
->lvds_setting_info
->lcd_panel_vres
;
79 viaparinfo
->lvds_setting_info2
->device_lcd_dualedge
=
80 viaparinfo
->lvds_setting_info
->device_lcd_dualedge
;
81 viaparinfo
->lvds_setting_info2
->LCDDithering
=
82 viaparinfo
->lvds_setting_info
->LCDDithering
;
85 static bool lvds_identify_integratedlvds(void)
87 if (viafb_display_hardware_layout
== HW_LAYOUT_LCD_EXTERNAL_LCD2
) {
88 /* Two dual channel LCD (Internal LVDS + External LVDS): */
89 /* If we have an external LVDS, such as VT1636, we should
90 have its chip ID already. */
91 if (viaparinfo
->chip_info
->lvds_chip_info
.lvds_chip_name
) {
92 viaparinfo
->chip_info
->lvds_chip_info2
.lvds_chip_name
=
94 DEBUG_MSG(KERN_INFO
"Support two dual channel LVDS! "
95 "(Internal LVDS + External LVDS)\n");
97 viaparinfo
->chip_info
->lvds_chip_info
.lvds_chip_name
=
99 DEBUG_MSG(KERN_INFO
"Not found external LVDS, "
100 "so can't support two dual channel LVDS!\n");
102 } else if (viafb_display_hardware_layout
== HW_LAYOUT_LCD1_LCD2
) {
103 /* Two single channel LCD (Internal LVDS + Internal LVDS): */
104 viaparinfo
->chip_info
->lvds_chip_info
.lvds_chip_name
=
106 viaparinfo
->chip_info
->lvds_chip_info2
.lvds_chip_name
=
108 DEBUG_MSG(KERN_INFO
"Support two single channel LVDS! "
109 "(Internal LVDS + Internal LVDS)\n");
110 } else if (viafb_display_hardware_layout
!= HW_LAYOUT_DVI_ONLY
) {
111 /* If we have found external LVDS, just use it,
112 otherwise, we will use internal LVDS as default. */
113 if (!viaparinfo
->chip_info
->lvds_chip_info
.lvds_chip_name
) {
114 viaparinfo
->chip_info
->lvds_chip_info
.lvds_chip_name
=
116 DEBUG_MSG(KERN_INFO
"Found Integrated LVDS!\n");
119 viaparinfo
->chip_info
->lvds_chip_info
.lvds_chip_name
=
120 NON_LVDS_TRANSMITTER
;
121 DEBUG_MSG(KERN_INFO
"Do not support LVDS!\n");
128 bool viafb_lvds_trasmitter_identify(void)
130 if (viafb_lvds_identify_vt1636(VIA_PORT_31
)) {
131 viaparinfo
->chip_info
->lvds_chip_info
.i2c_port
= VIA_PORT_31
;
133 "Found VIA VT1636 LVDS on port i2c 0x31\n");
135 if (viafb_lvds_identify_vt1636(VIA_PORT_2C
)) {
136 viaparinfo
->chip_info
->lvds_chip_info
.i2c_port
=
139 "Found VIA VT1636 LVDS on port gpio 0x2c\n");
143 if (viaparinfo
->chip_info
->gfx_chip_name
== UNICHROME_CX700
)
144 lvds_identify_integratedlvds();
146 if (viaparinfo
->chip_info
->lvds_chip_info
.lvds_chip_name
)
148 /* Check for VT1631: */
149 viaparinfo
->chip_info
->lvds_chip_info
.lvds_chip_name
= VT1631_LVDS
;
150 viaparinfo
->chip_info
->lvds_chip_info
.lvds_chip_slave_addr
=
151 VT1631_LVDS_I2C_ADDR
;
153 if (check_lvds_chip(VT1631_DEVICE_ID_REG
, VT1631_DEVICE_ID
)) {
154 DEBUG_MSG(KERN_INFO
"\n VT1631 LVDS ! \n");
155 DEBUG_MSG(KERN_INFO
"\n %2d",
156 viaparinfo
->chip_info
->lvds_chip_info
.lvds_chip_name
);
157 DEBUG_MSG(KERN_INFO
"\n %2d",
158 viaparinfo
->chip_info
->lvds_chip_info
.lvds_chip_name
);
162 viaparinfo
->chip_info
->lvds_chip_info
.lvds_chip_name
=
163 NON_LVDS_TRANSMITTER
;
164 viaparinfo
->chip_info
->lvds_chip_info
.lvds_chip_slave_addr
=
165 VT1631_LVDS_I2C_ADDR
;
169 static void fp_id_to_vindex(int panel_id
)
171 DEBUG_MSG(KERN_INFO
"fp_get_panel_id()\n");
173 if (panel_id
> LCD_PANEL_ID_MAXIMUM
)
174 viafb_lcd_panel_id
= panel_id
=
175 viafb_read_reg(VIACR
, CR3F
) & 0x0F;
179 viaparinfo
->lvds_setting_info
->lcd_panel_hres
= 640;
180 viaparinfo
->lvds_setting_info
->lcd_panel_vres
= 480;
181 viaparinfo
->lvds_setting_info
->device_lcd_dualedge
= 0;
182 viaparinfo
->lvds_setting_info
->LCDDithering
= 1;
185 viaparinfo
->lvds_setting_info
->lcd_panel_hres
= 800;
186 viaparinfo
->lvds_setting_info
->lcd_panel_vres
= 600;
187 viaparinfo
->lvds_setting_info
->device_lcd_dualedge
= 0;
188 viaparinfo
->lvds_setting_info
->LCDDithering
= 1;
191 viaparinfo
->lvds_setting_info
->lcd_panel_hres
= 1024;
192 viaparinfo
->lvds_setting_info
->lcd_panel_vres
= 768;
193 viaparinfo
->lvds_setting_info
->device_lcd_dualedge
= 0;
194 viaparinfo
->lvds_setting_info
->LCDDithering
= 1;
197 viaparinfo
->lvds_setting_info
->lcd_panel_hres
= 1280;
198 viaparinfo
->lvds_setting_info
->lcd_panel_vres
= 768;
199 viaparinfo
->lvds_setting_info
->device_lcd_dualedge
= 0;
200 viaparinfo
->lvds_setting_info
->LCDDithering
= 1;
203 viaparinfo
->lvds_setting_info
->lcd_panel_hres
= 1280;
204 viaparinfo
->lvds_setting_info
->lcd_panel_vres
= 1024;
205 viaparinfo
->lvds_setting_info
->device_lcd_dualedge
= 1;
206 viaparinfo
->lvds_setting_info
->LCDDithering
= 1;
209 viaparinfo
->lvds_setting_info
->lcd_panel_hres
= 1400;
210 viaparinfo
->lvds_setting_info
->lcd_panel_vres
= 1050;
211 viaparinfo
->lvds_setting_info
->device_lcd_dualedge
= 1;
212 viaparinfo
->lvds_setting_info
->LCDDithering
= 1;
215 viaparinfo
->lvds_setting_info
->lcd_panel_hres
= 1600;
216 viaparinfo
->lvds_setting_info
->lcd_panel_vres
= 1200;
217 viaparinfo
->lvds_setting_info
->device_lcd_dualedge
= 1;
218 viaparinfo
->lvds_setting_info
->LCDDithering
= 1;
221 viaparinfo
->lvds_setting_info
->lcd_panel_hres
= 800;
222 viaparinfo
->lvds_setting_info
->lcd_panel_vres
= 480;
223 viaparinfo
->lvds_setting_info
->device_lcd_dualedge
= 0;
224 viaparinfo
->lvds_setting_info
->LCDDithering
= 1;
227 viaparinfo
->lvds_setting_info
->lcd_panel_hres
= 1024;
228 viaparinfo
->lvds_setting_info
->lcd_panel_vres
= 768;
229 viaparinfo
->lvds_setting_info
->device_lcd_dualedge
= 1;
230 viaparinfo
->lvds_setting_info
->LCDDithering
= 1;
233 viaparinfo
->lvds_setting_info
->lcd_panel_hres
= 1024;
234 viaparinfo
->lvds_setting_info
->lcd_panel_vres
= 768;
235 viaparinfo
->lvds_setting_info
->device_lcd_dualedge
= 0;
236 viaparinfo
->lvds_setting_info
->LCDDithering
= 0;
239 viaparinfo
->lvds_setting_info
->lcd_panel_hres
= 1024;
240 viaparinfo
->lvds_setting_info
->lcd_panel_vres
= 768;
241 viaparinfo
->lvds_setting_info
->device_lcd_dualedge
= 1;
242 viaparinfo
->lvds_setting_info
->LCDDithering
= 0;
245 viaparinfo
->lvds_setting_info
->lcd_panel_hres
= 1280;
246 viaparinfo
->lvds_setting_info
->lcd_panel_vres
= 768;
247 viaparinfo
->lvds_setting_info
->device_lcd_dualedge
= 0;
248 viaparinfo
->lvds_setting_info
->LCDDithering
= 0;
251 viaparinfo
->lvds_setting_info
->lcd_panel_hres
= 1280;
252 viaparinfo
->lvds_setting_info
->lcd_panel_vres
= 1024;
253 viaparinfo
->lvds_setting_info
->device_lcd_dualedge
= 1;
254 viaparinfo
->lvds_setting_info
->LCDDithering
= 0;
257 viaparinfo
->lvds_setting_info
->lcd_panel_hres
= 1400;
258 viaparinfo
->lvds_setting_info
->lcd_panel_vres
= 1050;
259 viaparinfo
->lvds_setting_info
->device_lcd_dualedge
= 1;
260 viaparinfo
->lvds_setting_info
->LCDDithering
= 0;
263 viaparinfo
->lvds_setting_info
->lcd_panel_hres
= 1600;
264 viaparinfo
->lvds_setting_info
->lcd_panel_vres
= 1200;
265 viaparinfo
->lvds_setting_info
->device_lcd_dualedge
= 1;
266 viaparinfo
->lvds_setting_info
->LCDDithering
= 0;
269 viaparinfo
->lvds_setting_info
->lcd_panel_hres
= 1366;
270 viaparinfo
->lvds_setting_info
->lcd_panel_vres
= 768;
271 viaparinfo
->lvds_setting_info
->device_lcd_dualedge
= 0;
272 viaparinfo
->lvds_setting_info
->LCDDithering
= 0;
275 viaparinfo
->lvds_setting_info
->lcd_panel_hres
= 1024;
276 viaparinfo
->lvds_setting_info
->lcd_panel_vres
= 600;
277 viaparinfo
->lvds_setting_info
->device_lcd_dualedge
= 0;
278 viaparinfo
->lvds_setting_info
->LCDDithering
= 1;
281 viaparinfo
->lvds_setting_info
->lcd_panel_hres
= 1280;
282 viaparinfo
->lvds_setting_info
->lcd_panel_vres
= 768;
283 viaparinfo
->lvds_setting_info
->device_lcd_dualedge
= 1;
284 viaparinfo
->lvds_setting_info
->LCDDithering
= 1;
287 viaparinfo
->lvds_setting_info
->lcd_panel_hres
= 1280;
288 viaparinfo
->lvds_setting_info
->lcd_panel_vres
= 800;
289 viaparinfo
->lvds_setting_info
->device_lcd_dualedge
= 0;
290 viaparinfo
->lvds_setting_info
->LCDDithering
= 1;
293 viaparinfo
->lvds_setting_info
->lcd_panel_hres
= 1360;
294 viaparinfo
->lvds_setting_info
->lcd_panel_vres
= 768;
295 viaparinfo
->lvds_setting_info
->device_lcd_dualedge
= 0;
296 viaparinfo
->lvds_setting_info
->LCDDithering
= 0;
299 viaparinfo
->lvds_setting_info
->lcd_panel_hres
= 1280;
300 viaparinfo
->lvds_setting_info
->lcd_panel_vres
= 768;
301 viaparinfo
->lvds_setting_info
->device_lcd_dualedge
= 1;
302 viaparinfo
->lvds_setting_info
->LCDDithering
= 0;
305 viaparinfo
->lvds_setting_info
->lcd_panel_hres
= 480;
306 viaparinfo
->lvds_setting_info
->lcd_panel_vres
= 640;
307 viaparinfo
->lvds_setting_info
->device_lcd_dualedge
= 0;
308 viaparinfo
->lvds_setting_info
->LCDDithering
= 1;
311 /* OLPC XO-1.5 panel */
312 viaparinfo
->lvds_setting_info
->lcd_panel_hres
= 1200;
313 viaparinfo
->lvds_setting_info
->lcd_panel_vres
= 900;
314 viaparinfo
->lvds_setting_info
->device_lcd_dualedge
= 0;
315 viaparinfo
->lvds_setting_info
->LCDDithering
= 0;
318 viaparinfo
->lvds_setting_info
->lcd_panel_hres
= 800;
319 viaparinfo
->lvds_setting_info
->lcd_panel_vres
= 600;
320 viaparinfo
->lvds_setting_info
->device_lcd_dualedge
= 0;
321 viaparinfo
->lvds_setting_info
->LCDDithering
= 1;
325 static int lvds_register_read(int index
)
329 viafb_i2c_readbyte(VIA_PORT_2C
,
330 (u8
) viaparinfo
->chip_info
->lvds_chip_info
.lvds_chip_slave_addr
,
335 static void load_lcd_scaling(int set_hres
, int set_vres
, int panel_hres
,
339 int viafb_load_reg_num
;
340 struct io_register
*reg
= NULL
;
342 DEBUG_MSG(KERN_INFO
"load_lcd_scaling()!!\n");
344 /* LCD Scaling Enable */
345 viafb_write_reg_mask(CR79
, VIACR
, 0x07, BIT0
+ BIT1
+ BIT2
);
347 /* Check if expansion for horizontal */
348 if (set_hres
< panel_hres
) {
349 /* Load Horizontal Scaling Factor */
350 switch (viaparinfo
->chip_info
->gfx_chip_name
) {
351 case UNICHROME_CLE266
:
354 CLE266_LCD_HOR_SCF_FORMULA(set_hres
, panel_hres
);
356 lcd_scaling_factor_CLE
.lcd_hor_scaling_factor
.
358 reg
= lcd_scaling_factor_CLE
.lcd_hor_scaling_factor
.reg
;
359 viafb_load_reg(reg_value
,
360 viafb_load_reg_num
, reg
, VIACR
);
363 case UNICHROME_PM800
:
364 case UNICHROME_CN700
:
365 case UNICHROME_CX700
:
366 case UNICHROME_K8M890
:
367 case UNICHROME_P4M890
:
368 case UNICHROME_P4M900
:
369 case UNICHROME_CN750
:
370 case UNICHROME_VX800
:
371 case UNICHROME_VX855
:
372 case UNICHROME_VX900
:
374 K800_LCD_HOR_SCF_FORMULA(set_hres
, panel_hres
);
375 /* Horizontal scaling enabled */
376 viafb_write_reg_mask(CRA2
, VIACR
, 0xC0, BIT7
+ BIT6
);
378 lcd_scaling_factor
.lcd_hor_scaling_factor
.reg_num
;
379 reg
= lcd_scaling_factor
.lcd_hor_scaling_factor
.reg
;
380 viafb_load_reg(reg_value
,
381 viafb_load_reg_num
, reg
, VIACR
);
385 DEBUG_MSG(KERN_INFO
"Horizontal Scaling value = %d", reg_value
);
387 /* Horizontal scaling disabled */
388 viafb_write_reg_mask(CRA2
, VIACR
, 0x00, BIT7
);
391 /* Check if expansion for vertical */
392 if (set_vres
< panel_vres
) {
393 /* Load Vertical Scaling Factor */
394 switch (viaparinfo
->chip_info
->gfx_chip_name
) {
395 case UNICHROME_CLE266
:
398 CLE266_LCD_VER_SCF_FORMULA(set_vres
, panel_vres
);
400 lcd_scaling_factor_CLE
.lcd_ver_scaling_factor
.
402 reg
= lcd_scaling_factor_CLE
.lcd_ver_scaling_factor
.reg
;
403 viafb_load_reg(reg_value
,
404 viafb_load_reg_num
, reg
, VIACR
);
407 case UNICHROME_PM800
:
408 case UNICHROME_CN700
:
409 case UNICHROME_CX700
:
410 case UNICHROME_K8M890
:
411 case UNICHROME_P4M890
:
412 case UNICHROME_P4M900
:
413 case UNICHROME_CN750
:
414 case UNICHROME_VX800
:
415 case UNICHROME_VX855
:
416 case UNICHROME_VX900
:
418 K800_LCD_VER_SCF_FORMULA(set_vres
, panel_vres
);
419 /* Vertical scaling enabled */
420 viafb_write_reg_mask(CRA2
, VIACR
, 0x08, BIT3
);
422 lcd_scaling_factor
.lcd_ver_scaling_factor
.reg_num
;
423 reg
= lcd_scaling_factor
.lcd_ver_scaling_factor
.reg
;
424 viafb_load_reg(reg_value
,
425 viafb_load_reg_num
, reg
, VIACR
);
429 DEBUG_MSG(KERN_INFO
"Vertical Scaling value = %d", reg_value
);
431 /* Vertical scaling disabled */
432 viafb_write_reg_mask(CRA2
, VIACR
, 0x00, BIT3
);
436 static void via_pitch_alignment_patch_lcd(int iga_path
, int hres
, int bpp
)
438 unsigned char cr13
, cr35
, cr65
, cr66
, cr67
;
439 unsigned long dwScreenPitch
= 0;
440 unsigned long dwPitch
;
442 dwPitch
= hres
* (bpp
>> 3);
443 if (dwPitch
& 0x1F) {
444 dwScreenPitch
= ((dwPitch
+ 31) & ~31) >> 3;
445 if (iga_path
== IGA2
) {
447 cr66
= (unsigned char)(dwScreenPitch
& 0xFF);
448 viafb_write_reg(CR66
, VIACR
, cr66
);
449 cr67
= viafb_read_reg(VIACR
, CR67
) & 0xFC;
452 char)((dwScreenPitch
& 0x300) >> 8);
453 viafb_write_reg(CR67
, VIACR
, cr67
);
457 cr67
= viafb_read_reg(VIACR
, CR67
) & 0xF3;
458 cr67
|= (unsigned char)((dwScreenPitch
& 0x600) >> 7);
459 viafb_write_reg(CR67
, VIACR
, cr67
);
460 cr65
= (unsigned char)((dwScreenPitch
>> 1) & 0xFF);
462 viafb_write_reg(CR65
, VIACR
, cr65
);
465 cr13
= (unsigned char)(dwScreenPitch
& 0xFF);
466 viafb_write_reg(CR13
, VIACR
, cr13
);
467 cr35
= viafb_read_reg(VIACR
, CR35
) & 0x1F;
470 char)((dwScreenPitch
& 0x700) >> 3);
471 viafb_write_reg(CR35
, VIACR
, cr35
);
476 static void lcd_patch_skew_dvp0(struct lvds_setting_information
478 struct lvds_chip_information
*plvds_chip_info
)
480 if (VT1636_LVDS
== plvds_chip_info
->lvds_chip_name
) {
481 switch (viaparinfo
->chip_info
->gfx_chip_name
) {
482 case UNICHROME_P4M900
:
483 viafb_vt1636_patch_skew_on_vt3364(plvds_setting_info
,
486 case UNICHROME_P4M890
:
487 viafb_vt1636_patch_skew_on_vt3327(plvds_setting_info
,
493 static void lcd_patch_skew_dvp1(struct lvds_setting_information
495 struct lvds_chip_information
*plvds_chip_info
)
497 if (VT1636_LVDS
== plvds_chip_info
->lvds_chip_name
) {
498 switch (viaparinfo
->chip_info
->gfx_chip_name
) {
499 case UNICHROME_CX700
:
500 viafb_vt1636_patch_skew_on_vt3324(plvds_setting_info
,
506 static void lcd_patch_skew(struct lvds_setting_information
507 *plvds_setting_info
, struct lvds_chip_information
*plvds_chip_info
)
509 DEBUG_MSG(KERN_INFO
"lcd_patch_skew\n");
510 switch (plvds_chip_info
->output_interface
) {
512 lcd_patch_skew_dvp0(plvds_setting_info
, plvds_chip_info
);
515 lcd_patch_skew_dvp1(plvds_setting_info
, plvds_chip_info
);
517 case INTERFACE_DFP_LOW
:
518 if (UNICHROME_P4M900
== viaparinfo
->chip_info
->gfx_chip_name
) {
519 viafb_write_reg_mask(CR99
, VIACR
, 0x08,
520 BIT0
+ BIT1
+ BIT2
+ BIT3
);
527 void viafb_lcd_set_mode(const struct fb_var_screeninfo
*var
, u16 cxres
,
528 u16 cyres
, struct lvds_setting_information
*plvds_setting_info
,
529 struct lvds_chip_information
*plvds_chip_info
)
531 int set_iga
= plvds_setting_info
->iga_path
;
532 int mode_bpp
= var
->bits_per_pixel
;
533 int set_hres
= cxres
? cxres
: var
->xres
;
534 int set_vres
= cyres
? cyres
: var
->yres
;
535 int panel_hres
= plvds_setting_info
->lcd_panel_hres
;
536 int panel_vres
= plvds_setting_info
->lcd_panel_vres
;
538 struct via_display_timing timing
;
539 struct fb_var_screeninfo panel_var
;
540 const struct fb_videomode
*mode_crt_table
, *panel_crt_table
;
542 DEBUG_MSG(KERN_INFO
"viafb_lcd_set_mode!!\n");
544 mode_crt_table
= viafb_get_best_mode(set_hres
, set_vres
, 60);
545 /* Get panel table Pointer */
546 panel_crt_table
= viafb_get_best_mode(panel_hres
, panel_vres
, 60);
547 viafb_fill_var_timing_info(&panel_var
, panel_crt_table
);
548 DEBUG_MSG(KERN_INFO
"bellow viafb_lcd_set_mode!!\n");
549 if (VT1636_LVDS
== plvds_chip_info
->lvds_chip_name
)
550 viafb_init_lvds_vt1636(plvds_setting_info
, plvds_chip_info
);
551 clock
= PICOS2KHZ(panel_crt_table
->pixclock
) * 1000;
552 plvds_setting_info
->vclk
= clock
;
554 if (set_iga
== IGA2
&& (set_hres
< panel_hres
|| set_vres
< panel_vres
)
555 && plvds_setting_info
->display_method
== LCD_EXPANDSION
) {
556 timing
= var_to_timing(&panel_var
, panel_hres
, panel_vres
);
557 load_lcd_scaling(set_hres
, set_vres
, panel_hres
, panel_vres
);
559 timing
= var_to_timing(&panel_var
, set_hres
, set_vres
);
561 /* disable scaling */
562 via_write_reg_mask(VIACR
, 0x79, 0x00,
567 via_set_primary_timing(&timing
);
568 else if (set_iga
== IGA2
)
569 via_set_secondary_timing(&timing
);
571 /* Fetch count for IGA2 only */
572 viafb_load_fetch_count_reg(set_hres
, mode_bpp
/ 8, set_iga
);
574 if ((viaparinfo
->chip_info
->gfx_chip_name
!= UNICHROME_CLE266
)
575 && (viaparinfo
->chip_info
->gfx_chip_name
!= UNICHROME_K400
))
576 viafb_load_FIFO_reg(set_iga
, set_hres
, set_vres
);
579 viafb_set_vclock(clock
, set_iga
);
580 lcd_patch_skew(plvds_setting_info
, plvds_chip_info
);
582 /* If K8M800, enable LCD Prefetch Mode. */
583 if ((viaparinfo
->chip_info
->gfx_chip_name
== UNICHROME_K800
)
584 || (UNICHROME_K8M890
== viaparinfo
->chip_info
->gfx_chip_name
))
585 viafb_write_reg_mask(CR6A
, VIACR
, 0x01, BIT0
);
587 /* Patch for non 32bit alignment mode */
588 via_pitch_alignment_patch_lcd(plvds_setting_info
->iga_path
, set_hres
,
589 var
->bits_per_pixel
);
592 static void integrated_lvds_disable(struct lvds_setting_information
594 struct lvds_chip_information
*plvds_chip_info
)
596 bool turn_off_first_powersequence
= false;
597 bool turn_off_second_powersequence
= false;
598 if (INTERFACE_LVDS0LVDS1
== plvds_chip_info
->output_interface
)
599 turn_off_first_powersequence
= true;
600 if (INTERFACE_LVDS0
== plvds_chip_info
->output_interface
)
601 turn_off_first_powersequence
= true;
602 if (INTERFACE_LVDS1
== plvds_chip_info
->output_interface
)
603 turn_off_second_powersequence
= true;
604 if (turn_off_second_powersequence
) {
605 /* Use second power sequence control: */
607 /* Turn off power sequence. */
608 viafb_write_reg_mask(CRD4
, VIACR
, 0, BIT1
);
610 /* Turn off back light. */
611 viafb_write_reg_mask(CRD3
, VIACR
, 0xC0, BIT6
+ BIT7
);
613 if (turn_off_first_powersequence
) {
614 /* Use first power sequence control: */
616 /* Turn off power sequence. */
617 viafb_write_reg_mask(CR6A
, VIACR
, 0, BIT3
);
619 /* Turn off back light. */
620 viafb_write_reg_mask(CR91
, VIACR
, 0xC0, BIT6
+ BIT7
);
623 /* Power off LVDS channel. */
624 switch (plvds_chip_info
->output_interface
) {
625 case INTERFACE_LVDS0
:
627 viafb_write_reg_mask(CRD2
, VIACR
, 0x80, BIT7
);
631 case INTERFACE_LVDS1
:
633 viafb_write_reg_mask(CRD2
, VIACR
, 0x40, BIT6
);
637 case INTERFACE_LVDS0LVDS1
:
639 viafb_write_reg_mask(CRD2
, VIACR
, 0xC0, BIT6
+ BIT7
);
645 static void integrated_lvds_enable(struct lvds_setting_information
647 struct lvds_chip_information
*plvds_chip_info
)
649 DEBUG_MSG(KERN_INFO
"integrated_lvds_enable, out_interface:%d\n",
650 plvds_chip_info
->output_interface
);
651 if (plvds_setting_info
->lcd_mode
== LCD_SPWG
)
652 viafb_write_reg_mask(CRD2
, VIACR
, 0x00, BIT0
+ BIT1
);
654 viafb_write_reg_mask(CRD2
, VIACR
, 0x03, BIT0
+ BIT1
);
656 switch (plvds_chip_info
->output_interface
) {
657 case INTERFACE_LVDS0LVDS1
:
658 case INTERFACE_LVDS0
:
659 /* Use first power sequence control: */
660 /* Use hardware control power sequence. */
661 viafb_write_reg_mask(CR91
, VIACR
, 0, BIT0
);
662 /* Turn on back light. */
663 viafb_write_reg_mask(CR91
, VIACR
, 0, BIT6
+ BIT7
);
664 /* Turn on hardware power sequence. */
665 viafb_write_reg_mask(CR6A
, VIACR
, 0x08, BIT3
);
667 case INTERFACE_LVDS1
:
668 /* Use second power sequence control: */
669 /* Use hardware control power sequence. */
670 viafb_write_reg_mask(CRD3
, VIACR
, 0, BIT0
);
671 /* Turn on back light. */
672 viafb_write_reg_mask(CRD3
, VIACR
, 0, BIT6
+ BIT7
);
673 /* Turn on hardware power sequence. */
674 viafb_write_reg_mask(CRD4
, VIACR
, 0x02, BIT1
);
678 /* Power on LVDS channel. */
679 switch (plvds_chip_info
->output_interface
) {
680 case INTERFACE_LVDS0
:
682 viafb_write_reg_mask(CRD2
, VIACR
, 0, BIT7
);
686 case INTERFACE_LVDS1
:
688 viafb_write_reg_mask(CRD2
, VIACR
, 0, BIT6
);
692 case INTERFACE_LVDS0LVDS1
:
694 viafb_write_reg_mask(CRD2
, VIACR
, 0, BIT6
+ BIT7
);
700 void viafb_lcd_disable(void)
703 if (viaparinfo
->chip_info
->gfx_chip_name
== UNICHROME_CLE266
) {
704 lcd_powersequence_off();
706 viafb_write_reg_mask(SR1E
, VIASR
, 0x00, 0x30);
707 } else if (viaparinfo
->chip_info
->gfx_chip_name
== UNICHROME_CX700
) {
709 && (INTEGRATED_LVDS
==
710 viaparinfo
->chip_info
->lvds_chip_info2
.lvds_chip_name
))
711 integrated_lvds_disable(viaparinfo
->lvds_setting_info
,
712 &viaparinfo
->chip_info
->lvds_chip_info2
);
713 if (INTEGRATED_LVDS
==
714 viaparinfo
->chip_info
->lvds_chip_info
.lvds_chip_name
)
715 integrated_lvds_disable(viaparinfo
->lvds_setting_info
,
716 &viaparinfo
->chip_info
->lvds_chip_info
);
717 if (VT1636_LVDS
== viaparinfo
->chip_info
->
718 lvds_chip_info
.lvds_chip_name
)
719 viafb_disable_lvds_vt1636(viaparinfo
->lvds_setting_info
,
720 &viaparinfo
->chip_info
->lvds_chip_info
);
721 } else if (VT1636_LVDS
==
722 viaparinfo
->chip_info
->lvds_chip_info
.lvds_chip_name
) {
723 viafb_disable_lvds_vt1636(viaparinfo
->lvds_setting_info
,
724 &viaparinfo
->chip_info
->lvds_chip_info
);
727 viafb_write_reg_mask(SR3D
, VIASR
, 0x00, 0x20);
728 /* 24 bit DI data paht off */
729 viafb_write_reg_mask(CR91
, VIACR
, 0x80, 0x80);
732 /* Disable expansion bit */
733 viafb_write_reg_mask(CR79
, VIACR
, 0x00, 0x01);
734 /* Simultaneout disabled */
735 viafb_write_reg_mask(CR6B
, VIACR
, 0x00, 0x08);
738 static void set_lcd_output_path(int set_iga
, int output_interface
)
740 switch (output_interface
) {
742 if ((UNICHROME_K8M890
== viaparinfo
->chip_info
->gfx_chip_name
)
743 || (UNICHROME_P4M890
==
744 viaparinfo
->chip_info
->gfx_chip_name
))
745 viafb_write_reg_mask(CR97
, VIACR
, 0x84,
746 BIT7
+ BIT2
+ BIT1
+ BIT0
);
750 case INTERFACE_DFP_HIGH
:
751 case INTERFACE_DFP_LOW
:
753 viafb_write_reg(CR91
, VIACR
, 0x00);
758 void viafb_lcd_enable(void)
760 viafb_write_reg_mask(CR6B
, VIACR
, 0x00, BIT3
);
761 viafb_write_reg_mask(CR6A
, VIACR
, 0x08, BIT3
);
762 set_lcd_output_path(viaparinfo
->lvds_setting_info
->iga_path
,
763 viaparinfo
->chip_info
->lvds_chip_info
.output_interface
);
765 set_lcd_output_path(viaparinfo
->lvds_setting_info2
->iga_path
,
766 viaparinfo
->chip_info
->
767 lvds_chip_info2
.output_interface
);
769 if (viaparinfo
->chip_info
->gfx_chip_name
== UNICHROME_CLE266
) {
771 viafb_write_reg_mask(SR1E
, VIASR
, 0x30, 0x30);
772 lcd_powersequence_on();
773 } else if (viaparinfo
->chip_info
->gfx_chip_name
== UNICHROME_CX700
) {
774 if (viafb_LCD2_ON
&& (INTEGRATED_LVDS
==
775 viaparinfo
->chip_info
->lvds_chip_info2
.lvds_chip_name
))
776 integrated_lvds_enable(viaparinfo
->lvds_setting_info2
, \
777 &viaparinfo
->chip_info
->lvds_chip_info2
);
778 if (INTEGRATED_LVDS
==
779 viaparinfo
->chip_info
->lvds_chip_info
.lvds_chip_name
)
780 integrated_lvds_enable(viaparinfo
->lvds_setting_info
,
781 &viaparinfo
->chip_info
->lvds_chip_info
);
782 if (VT1636_LVDS
== viaparinfo
->chip_info
->
783 lvds_chip_info
.lvds_chip_name
)
784 viafb_enable_lvds_vt1636(viaparinfo
->
785 lvds_setting_info
, &viaparinfo
->chip_info
->
787 } else if (VT1636_LVDS
==
788 viaparinfo
->chip_info
->lvds_chip_info
.lvds_chip_name
) {
789 viafb_enable_lvds_vt1636(viaparinfo
->lvds_setting_info
,
790 &viaparinfo
->chip_info
->lvds_chip_info
);
793 viafb_write_reg_mask(SR3D
, VIASR
, 0x20, 0x20);
794 /* 24 bit DI data paht on */
795 viafb_write_reg_mask(CR91
, VIACR
, 0x00, 0x80);
797 viafb_write_reg_mask(CR6A
, VIACR
, 0x48, 0x48);
801 static void lcd_powersequence_off(void)
805 /* Software control power sequence */
806 viafb_write_reg_mask(CR91
, VIACR
, 0x11, 0x11);
808 for (i
= 0; i
< 3; i
++) {
809 mask
= PowerSequenceOff
[0][i
];
810 data
= PowerSequenceOff
[1][i
] & mask
;
811 viafb_write_reg_mask(CR91
, VIACR
, (u8
) data
, (u8
) mask
);
812 udelay(PowerSequenceOff
[2][i
]);
816 viafb_write_reg_mask(CR6A
, VIACR
, 0x00, 0x08);
819 static void lcd_powersequence_on(void)
823 /* Software control power sequence */
824 viafb_write_reg_mask(CR91
, VIACR
, 0x11, 0x11);
827 viafb_write_reg_mask(CR6A
, VIACR
, 0x08, 0x08);
829 for (i
= 0; i
< 3; i
++) {
830 mask
= PowerSequenceOn
[0][i
];
831 data
= PowerSequenceOn
[1][i
] & mask
;
832 viafb_write_reg_mask(CR91
, VIACR
, (u8
) data
, (u8
) mask
);
833 udelay(PowerSequenceOn
[2][i
]);
839 static void fill_lcd_format(void)
841 u8 bdithering
= 0, bdual
= 0;
843 if (viaparinfo
->lvds_setting_info
->device_lcd_dualedge
)
845 if (viaparinfo
->lvds_setting_info
->LCDDithering
)
847 /* Dual & Dithering */
848 viafb_write_reg_mask(CR88
, VIACR
, (bdithering
| bdual
), BIT4
+ BIT0
);
851 static void check_diport_of_integrated_lvds(
852 struct lvds_chip_information
*plvds_chip_info
,
853 struct lvds_setting_information
856 /* Determine LCD DI Port by hardware layout. */
857 switch (viafb_display_hardware_layout
) {
858 case HW_LAYOUT_LCD_ONLY
:
860 if (plvds_setting_info
->device_lcd_dualedge
) {
861 plvds_chip_info
->output_interface
=
862 INTERFACE_LVDS0LVDS1
;
864 plvds_chip_info
->output_interface
=
871 case HW_LAYOUT_DVI_ONLY
:
873 plvds_chip_info
->output_interface
= INTERFACE_NONE
;
877 case HW_LAYOUT_LCD1_LCD2
:
878 case HW_LAYOUT_LCD_EXTERNAL_LCD2
:
880 plvds_chip_info
->output_interface
=
881 INTERFACE_LVDS0LVDS1
;
885 case HW_LAYOUT_LCD_DVI
:
887 plvds_chip_info
->output_interface
= INTERFACE_LVDS1
;
893 plvds_chip_info
->output_interface
= INTERFACE_LVDS1
;
899 "Display Hardware Layout: 0x%x, LCD DI Port: 0x%x\n",
900 viafb_display_hardware_layout
,
901 plvds_chip_info
->output_interface
);
904 void viafb_init_lvds_output_interface(struct lvds_chip_information
906 struct lvds_setting_information
909 if (INTERFACE_NONE
!= plvds_chip_info
->output_interface
) {
910 /*Do nothing, lcd port is specified by module parameter */
914 switch (plvds_chip_info
->lvds_chip_name
) {
917 switch (viaparinfo
->chip_info
->gfx_chip_name
) {
918 case UNICHROME_CX700
:
919 plvds_chip_info
->output_interface
= INTERFACE_DVP1
;
921 case UNICHROME_CN700
:
922 plvds_chip_info
->output_interface
= INTERFACE_DFP_LOW
;
925 plvds_chip_info
->output_interface
= INTERFACE_DVP0
;
930 case INTEGRATED_LVDS
:
931 check_diport_of_integrated_lvds(plvds_chip_info
,
936 switch (viaparinfo
->chip_info
->gfx_chip_name
) {
937 case UNICHROME_K8M890
:
938 case UNICHROME_P4M900
:
939 case UNICHROME_P4M890
:
940 plvds_chip_info
->output_interface
= INTERFACE_DFP_LOW
;
943 plvds_chip_info
->output_interface
= INTERFACE_DFP
;
950 bool viafb_lcd_get_mobile_state(bool *mobile
)
952 unsigned char __iomem
*romptr
, *tableptr
, *biosptr
;
955 const u32 romaddr
= 0x000C0000;
958 biosptr
= ioremap(romaddr
, 0x10000);
959 start_pattern
= readw(biosptr
);
961 /* Compare pattern */
962 if (start_pattern
== 0xAA55) {
963 /* Get the start of Table */
964 /* 0x1B means BIOS offset position */
965 romptr
= biosptr
+ 0x1B;
966 tableptr
= biosptr
+ readw(romptr
);
968 /* Get the start of biosver structure */
969 /* 18 means BIOS version position. */
970 romptr
= tableptr
+ 18;
971 romptr
= biosptr
+ readw(romptr
);
973 /* The offset should be 44, but the
974 actual image is less three char. */
978 core_base
= readb(romptr
);